Skip to content

Commit a08f1ca

Browse files
committed
accessto myevents, delete ok, update ok que sur ponctualEvent
1 parent 4cb6ce9 commit a08f1ca

File tree

5 files changed

+170
-82
lines changed

5 files changed

+170
-82
lines changed

Zenergy/Zenergy/Controllers/ApiControllers/ponctualEventsController.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public async Task<IHttpActionResult> findPonctualEventsByManagerId(int managerId
6262
[HttpPut]
6363
[Route("api/ponctualEvents/{id}")]
6464
[ResponseType(typeof(void))]
65+
[Authorize(Roles = "Manager")]
6566
public async Task<IHttpActionResult> PutponctualEvent(int id, ponctualEvent ponctualEvent)
6667
{
6768
if (!ModelState.IsValid)
@@ -74,7 +75,7 @@ public async Task<IHttpActionResult> PutponctualEvent(int id, ponctualEvent ponc
7475
return BadRequest();
7576
}
7677

77-
db.Entry(ponctualEvent.@event).State = EntityState.Modified;
78+
//db.Entry(ponctualEvent.@event).State = EntityState.Modified;
7879
db.Entry(ponctualEvent).State = EntityState.Modified;
7980

8081
try
@@ -97,6 +98,7 @@ public async Task<IHttpActionResult> PutponctualEvent(int id, ponctualEvent ponc
9798
}
9899

99100
// POST: api/ponctualEvents
101+
[Authorize(Roles = "Manager")]
100102
[ResponseType(typeof(ponctualEvent))]
101103
public async Task<IHttpActionResult> PostponctualEvent(ponctualEvent ponctualEvent)
102104
{
@@ -127,7 +129,10 @@ public async Task<IHttpActionResult> PostponctualEvent(ponctualEvent ponctualEve
127129
}
128130

129131
// DELETE: api/ponctualEvents/5
132+
[HttpDelete]
133+
[Route("api/ponctualEvents/{id}")]
130134
[ResponseType(typeof(ponctualEvent))]
135+
[Authorize(Roles = "Manager")]
131136
public async Task<IHttpActionResult> DeleteponctualEvent(int id)
132137
{
133138
ponctualEvent ponctualEvent = await db.ponctualEvent.FindAsync(id);

Zenergy/Zenergy/Pages/eventsManagement.html

+32-21
Original file line numberDiff line numberDiff line change
@@ -56,33 +56,44 @@ <h3 class="modal-title">Update {{eventToUpdate.event.eventName}}</h3>
5656
</script>
5757
<!-- UpdateModal end -->
5858

59+
<!-- Delete modal view -->
60+
<script type="text/ng-template" id="deleteModalContent.html">
61+
<div class="modal-header">
62+
<h3 class="modal-title">You are about to cancel {{eventToDelete.event.eventName}}</h3>
63+
</div>
64+
<div class="modal-footer">
65+
<button class="btn btn-warning" type="button" ng-click="deleteCancel()">Cancel</button>
66+
<button class="btn btn-primary" type="button" ng-click="deleteOk()">Continue</button>
67+
</div>
68+
</script>
69+
<!-- UpdateModal end -->
5970

6071
<div class="panel panel-default">
6172
<!-- Default panel contents -->
6273
<div class="panel-heading">Here are the events you created</div>
6374

64-
<!-- Table -->
65-
<table class="table">
66-
<tr>
67-
<th>Event Name</th>
68-
<th>Activity</th>
69-
<th>Room</th>
70-
<th>Date</th>
71-
<th>Time</th>
72-
<th></th>
73-
<th></th>
74-
</tr>
75-
<tr ng-repeat="ponctual in filtered = (ponctualEvents | filter: query)">
76-
<td>{{ponctual.event.eventName}}</td>
77-
<td>{{ponctual.event.activity.activityName}}</td>
78-
<td>{{ponctual.event.room.roomName}}</td>
79-
<td>{{ponctual.eventDate | date:'yyyy-MM-dd'}}</td>
80-
<td>{{ponctual.event.timeBegin}}</td>
81-
<td><input class="btn btn-warning btn-sm" value="Update" ng-click="open(ponctual)" /></td>
82-
<td><button type="button" class="btn btn-danger">Delete</button></td>
83-
</table>
75+
<!-- Table -->
76+
<table class="table">
77+
<tr>
78+
<th>Event Name</th>
79+
<th>Activity</th>
80+
<th>Room</th>
81+
<th>Date</th>
82+
<th>Time</th>
83+
<th></th>
84+
<th></th>
85+
</tr>
86+
<tr ng-repeat="ponctual in filtered = (ponctualEvents | filter: query)">
87+
<td>{{ponctual.event.eventName}}</td>
88+
<td>{{ponctual.event.activity.activityName}}</td>
89+
<td>{{ponctual.event.room.roomName}}</td>
90+
<td>{{ponctual.eventDate | date:'yyyy-MM-dd'}}</td>
91+
<td>{{ponctual.event.timeBegin}}</td>
92+
<td><input class="btn btn-warning btn-xs" value="Update" ng-click="open(ponctual)" /></td>
93+
<td><input class="btn btn-danger btn-xs" value="Delete" ng-click="openDeleteModal(ponctual)" /></td>
94+
</table>
95+
</div>
8496
</div>
85-
</div>
8697
<div class="row">
8798
<a href="#/CreateEvent" class="btn btn-success btn-lg">Create a new event!</a>
8899
</div>

Zenergy/Zenergy/Scripts/Controllers/eventsManagementPageController.js

+64-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
zenergyApp.controller("eventsManagementPageController", ["$scope", "$http", "tokenService", "$window", "$uibModal", "$location", function ($scope, $http, tokenService, $window, $uibModal, $location) {
1+
zenergyApp.controller("eventsManagementPageController", ["$scope", "$http", "tokenService", "$resource", "$window", "$uibModal", "$location", function ($scope, $http, tokenService, $resource, $window, $uibModal, $location) {
22

33
if ($scope.isManager()) {
44
// Get manager events
@@ -15,8 +15,7 @@
1515
console.log($scope.ponctualEvents);
1616
});
1717

18-
19-
// modal management
18+
// Update modal management
2019
$scope.open = function (ponctual) {
2120

2221
$scope.eventToUpdate = ponctual;
@@ -42,7 +41,7 @@
4241
eventToUpdate.event.roomId = document.getElementById("roomSelect").value;
4342

4443
console.log(eventToUpdate);
45-
44+
4645
var response = $http({
4746
url: '/api/ponctualEvents/' + eventToUpdate.eventId,
4847
method: 'PUT',
@@ -71,6 +70,52 @@
7170
}, function errorCallback(response) {
7271
bootbox.alert("There has been an error during the update.");
7372
});
73+
74+
/*$http.put('/api/ponctualEvents/' + eventToUpdate.eventId, eventToUpdate)
75+
.success(function (data, status, headers) {
76+
bootbox.alert("Your event is updated!", function () {
77+
window.location.reload(true);
78+
});
79+
})
80+
.error(function () {
81+
bootbox.alert("There has been an error during the update.");
82+
});
83+
84+
/*var Event = $resource('api/regularEvents/:eventId', { eventId: '@id' }, {
85+
update: {
86+
method: 'PUT' // this method issues a PUT request
87+
}
88+
});
89+
Event.update({ eventId: eventToUpdate.eventId }, eventToUpdate);*/
90+
91+
}, function () {
92+
});
93+
};
94+
95+
// Delete modal management
96+
$scope.openDeleteModal = function (ponctual) {
97+
98+
$scope.eventToDelete = ponctual;
99+
100+
var modalInstance = $uibModal.open({
101+
animation: true,
102+
templateUrl: 'deleteModalContent.html',
103+
controller: 'DeleteModalInstanceCtrl',
104+
resolve: {
105+
eventToDelete: function () {
106+
return $scope.eventToDelete;
107+
}
108+
}
109+
});
110+
111+
modalInstance.result.then(function (eventToDelete) {
112+
// Delete Event
113+
console.log(eventToDelete);
114+
$http.delete('/api/ponctualEvents/' + eventToDelete.eventId).success(function () {
115+
bootbox.alert("Your event is deleted!", function () {
116+
window.location.reload(true);
117+
});
118+
});
74119
}, function () {
75120
});
76121
};
@@ -79,6 +124,7 @@
79124
$location.path("/");
80125
}]);
81126

127+
// Update modal controller
82128
zenergyApp.controller('UpdateModalInstanceCtrl', function ($scope, $http, $uibModalInstance, eventToUpdate) {
83129

84130
$scope.eventToUpdate = $.extend(true, {}, eventToUpdate);
@@ -105,4 +151,18 @@ zenergyApp.controller('UpdateModalInstanceCtrl', function ($scope, $http, $uibMo
105151
$scope.cancel = function () {
106152
$uibModalInstance.dismiss('cancel');
107153
};
154+
});
155+
156+
// Delete modal controller
157+
zenergyApp.controller('DeleteModalInstanceCtrl', function ($scope, $uibModalInstance, eventToDelete) {
158+
159+
$scope.eventToDelete = eventToDelete;
160+
161+
$scope.deleteOk = function () {
162+
$uibModalInstance.close(eventToDelete);
163+
};
164+
165+
$scope.deleteCancel = function () {
166+
$uibModalInstance.dismiss('cancel');
167+
};
108168
});
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,70 @@
11
zenergyApp.controller("ponctualEventCreationPageController", ["$scope", "$http", "tokenService", "$window", "$location", function ($scope, $http, tokenService, $window, $location) {
22

3-
// Get activities
4-
var response = $http({
5-
url: '/api/activities/findByManagerId/' + tokenService.getUserId(),
6-
method: 'GET',
7-
headers: {
8-
'Content-Type': 'application/json'
9-
}
10-
}).then(function successCallback(response) {
11-
$scope.hasError = false;
12-
$scope.activities = [];
13-
$scope.activities = $.parseJSON(JSON.stringify(response.data));
14-
console.log($scope.activities);
15-
});
3+
if ($scope.isManager()) {
4+
// Get activities
5+
var response = $http({
6+
url: '/api/activities/findByManagerId/' + tokenService.getUserId(),
7+
method: 'GET',
8+
headers: {
9+
'Content-Type': 'application/json'
10+
}
11+
}).then(function successCallback(response) {
12+
$scope.hasError = false;
13+
$scope.activities = [];
14+
$scope.activities = $.parseJSON(JSON.stringify(response.data));
15+
console.log($scope.activities);
16+
});
1617

17-
// Get rooms
18-
var response = $http({
19-
url: '/api/rooms',
20-
method: 'GET',
21-
headers: {
22-
'Content-Type': 'application/json'
23-
}
24-
}).then(function successCallback(response) {
25-
$scope.hasError = false;
26-
$scope.rooms = [];
27-
$scope.rooms = $.parseJSON(JSON.stringify(response.data));
28-
console.log($scope.rooms);
29-
});
18+
// Get rooms
19+
var response = $http({
20+
url: '/api/rooms',
21+
method: 'GET',
22+
headers: {
23+
'Content-Type': 'application/json'
24+
}
25+
}).then(function successCallback(response) {
26+
$scope.hasError = false;
27+
$scope.rooms = [];
28+
$scope.rooms = $.parseJSON(JSON.stringify(response.data));
29+
console.log($scope.rooms);
30+
});
3031

31-
$scope.ponctualEvent = { eventId: 1, eventDate: new Date(), event: { eventId: 1, roomId: '', activityId: '', eventName: '', eventPrice: '', eventDurationHours: '', eventMaxPeople: '', eventDescription: '', timeBegin: '' } };
32+
$scope.ponctualEvent = { eventId: 1, eventDate: new Date(), event: { eventId: 1, roomId: '', activityId: '', eventName: '', eventPrice: '', eventDurationHours: '', eventMaxPeople: '', eventDescription: '', timeBegin: '' } };
3233

33-
$scope.createEvent = function () {
34-
//console.log($scope.ponctualEvent);
34+
$scope.createEvent = function () {
35+
//console.log($scope.ponctualEvent);
3536

36-
$scope.hasError = false;
37-
$scope.dateError = false;
37+
$scope.hasError = false;
38+
$scope.dateError = false;
3839

39-
var today = new Date();
40-
if ($scope.ponctualEvent.eventDate <= today) {
41-
$scope.hasError = true;
42-
$scope.dateError = true;
43-
}
40+
var today = new Date();
41+
if ($scope.ponctualEvent.eventDate <= today) {
42+
$scope.hasError = true;
43+
$scope.dateError = true;
44+
}
45+
46+
var date = new Date($scope.ponctualEvent.event.timeBegin);
47+
$scope.ponctualEvent.event.timeBegin = date.getHours().toString() + ":" + date.getMinutes().toString();
4448

45-
var date = new Date($scope.ponctualEvent.event.timeBegin);
46-
$scope.ponctualEvent.event.timeBegin = date.getHours().toString() + ":" + date.getMinutes().toString();
47-
48-
$scope.ponctualEvent.event.roomId = document.getElementById("roomSelect").value;
49-
$scope.ponctualEvent.event.activityId = document.getElementById("actSelect").value;
49+
$scope.ponctualEvent.event.roomId = document.getElementById("roomSelect").value;
50+
$scope.ponctualEvent.event.activityId = document.getElementById("actSelect").value;
5051

51-
if (!$scope.hasError)
52-
{
53-
var response = $http({
54-
url: '/api/ponctualEvents',
55-
method: 'POST',
56-
data: $scope.ponctualEvent,
57-
headers: {
58-
'Content-Type': 'application/json'
59-
}
60-
}).then(function successCallback(response) {
61-
bootbox.alert("Your event is now created!", function () {
62-
$location.path("/#/MyEvents");
52+
if (!$scope.hasError) {
53+
var response = $http({
54+
url: '/api/ponctualEvents',
55+
method: 'POST',
56+
data: $scope.ponctualEvent,
57+
headers: {
58+
'Content-Type': 'application/json'
59+
}
60+
}).then(function successCallback(response) {
61+
bootbox.alert("Your event is now created!", function () {
62+
$location.path("/#/MyEvents");
63+
});
64+
}, function errorCallback(response) {
65+
bootbox.alert("There has been an error during the event creation. Please check your event information.");
6366
});
64-
}, function errorCallback(response) {
65-
bootbox.alert("There has been an error during the event creation. Please check your event information.");
66-
});
67+
}
6768
}
6869
}
6970
}]);

Zenergy/Zenergy/Views/Shared/_Layout.cshtml

+11
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@
3636
</ul>
3737
</li>
3838
</ul>
39+
<ul class="nav navbar-nav navbar-right" ng-show="isAuthanticated() && isManager()">
40+
<li class="dropdown">
41+
<a class="dropdown-toggle" data-toggle="dropdown" href="">
42+
Manager Panel
43+
<span class="caret"></span>
44+
</a>
45+
<ul class="dropdown-menu">
46+
<li><a href="#MyEvents">My events</a></li>
47+
</ul>
48+
</li>
49+
</ul>
3950
<ul class="nav navbar-nav navbar-right" ng-show="isAuthanticated() && isAdmin()">
4051
<li class="dropdown">
4152
<a class="dropdown-toggle" data-toggle="dropdown" href="">

0 commit comments

Comments
 (0)