Skip to content

Commit acdb582

Browse files
committed
createEvent pages ready
1 parent d366054 commit acdb582

10 files changed

+387
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data;
4+
using System.Data.Entity;
5+
using System.Data.Entity.Infrastructure;
6+
using System.Linq;
7+
using System.Net;
8+
using System.Net.Http;
9+
using System.Threading.Tasks;
10+
using System.Web.Http;
11+
using System.Web.Http.Description;
12+
using Zenergy.Models;
13+
using Zenergy.Services;
14+
15+
namespace Zenergy.Controllers.ApiControllers
16+
{
17+
[Authorize]
18+
public class activitiesController : ApiController
19+
{
20+
private ZenergyContext db = new ZenergyContext();
21+
private ActivityService activityServices;
22+
23+
public activitiesController()
24+
{
25+
activityServices = new ActivityService(db);
26+
}
27+
28+
// GET: api/activities
29+
public IQueryable<activity> Getactivity()
30+
{
31+
return db.activity;
32+
}
33+
34+
// GET: api/activities/5
35+
[ResponseType(typeof(activity))]
36+
public IHttpActionResult Getactivity(int id)
37+
{
38+
activity activity = db.activity.Find(id);
39+
if (activity == null)
40+
{
41+
return NotFound();
42+
}
43+
44+
return Ok(activity);
45+
}
46+
47+
// GET: api/activities/findByManagerId/5
48+
[Route("api/activities/findByManagerId/{managerId}")]
49+
[HttpGet]
50+
[ResponseType(typeof(activity[]))]
51+
public async Task<IHttpActionResult> findActivitiesByManagerId(int managerId)
52+
{
53+
activity[] activities = await activityServices.findActivitiesByManagerId(managerId);
54+
if (activities == null)
55+
{
56+
return NotFound();
57+
}
58+
59+
return Ok(activities);
60+
}
61+
62+
// PUT: api/activities/5
63+
[ResponseType(typeof(void))]
64+
public IHttpActionResult Putactivity(int id, activity activity)
65+
{
66+
if (!ModelState.IsValid)
67+
{
68+
return BadRequest(ModelState);
69+
}
70+
71+
if (id != activity.activityId)
72+
{
73+
return BadRequest();
74+
}
75+
76+
db.Entry(activity).State = EntityState.Modified;
77+
78+
try
79+
{
80+
db.SaveChanges();
81+
}
82+
catch (DbUpdateConcurrencyException)
83+
{
84+
if (!activityExists(id))
85+
{
86+
return NotFound();
87+
}
88+
else
89+
{
90+
throw;
91+
}
92+
}
93+
94+
return StatusCode(HttpStatusCode.NoContent);
95+
}
96+
97+
// POST: api/activities
98+
[ResponseType(typeof(activity))]
99+
public IHttpActionResult Postactivity(activity activity)
100+
{
101+
if (!ModelState.IsValid)
102+
{
103+
return BadRequest(ModelState);
104+
}
105+
106+
db.activity.Add(activity);
107+
db.SaveChanges();
108+
109+
return CreatedAtRoute("DefaultApi", new { id = activity.activityId }, activity);
110+
}
111+
112+
// DELETE: api/activities/5
113+
[ResponseType(typeof(activity))]
114+
public IHttpActionResult Deleteactivity(int id)
115+
{
116+
activity activity = db.activity.Find(id);
117+
if (activity == null)
118+
{
119+
return NotFound();
120+
}
121+
122+
db.activity.Remove(activity);
123+
db.SaveChanges();
124+
125+
return Ok(activity);
126+
}
127+
128+
protected override void Dispose(bool disposing)
129+
{
130+
if (disposing)
131+
{
132+
db.Dispose();
133+
}
134+
base.Dispose(disposing);
135+
}
136+
137+
private bool activityExists(int id)
138+
{
139+
return db.activity.Count(e => e.activityId == id) > 0;
140+
}
141+
}
142+
}

Diff for: Zenergy/Zenergy/Pages/eventsManagement.html

+29-24
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
11
<h2>My events</h2>
22

33
<div class="container " ng-controller="accountManagementPageController">
4+
<div class="row">
5+
<div class="panel panel-default">
6+
<!-- Default panel contents -->
7+
<div class="panel-heading">Here are the events you created</div>
48

5-
<div class="panel panel-default">
6-
<!-- Default panel contents -->
7-
<div class="panel-heading">Here are the events you created</div>
8-
9-
<!-- Table -->
10-
<table class="table">
11-
<tr>
12-
<th>Event Name</th>
13-
<th>Activity</th>
14-
<th>Room</th>
15-
<th>Date</th>
16-
<th>Time</th>
17-
</tr>
18-
<tr ng-repeat="ponctual in filtered = (ponctualEvents | filter: query)">
19-
<td>{{ponctual.event.eventName}}</td>
20-
<td>{{ponctual.event.activity.activityName}}</td>
21-
<td>{{ponctual.event.room.roomName}}</td>
22-
<td>{{ponctual.eventDate | date:'yyyy-MM-dd'}}</td>
23-
<td>{{ponctual.event.timeBegin}}</td>
24-
<td><form ng-submit="updateEvent($index)"><input value="Update" type="submit" class="btn btn-warning"/></form></td>
25-
<td><button type="button" class="btn btn-danger">Delete</button></td>
26-
</tr>
27-
</table>
9+
<!-- Table -->
10+
<table class="table">
11+
<tr>
12+
<th>Event Name</th>
13+
<th>Activity</th>
14+
<th>Room</th>
15+
<th>Date</th>
16+
<th>Time</th>
17+
<th></th>
18+
<th></th>
19+
</tr>
20+
<tr ng-repeat="ponctual in filtered = (ponctualEvents | filter: query)">
21+
<td>{{ponctual.event.eventName}}</td>
22+
<td>{{ponctual.event.activity.activityName}}</td>
23+
<td>{{ponctual.event.room.roomName}}</td>
24+
<td>{{ponctual.eventDate | date:'yyyy-MM-dd'}}</td>
25+
<td>{{ponctual.event.timeBegin}}</td>
26+
<td><form ng-submit="updateEvent($index)"><input value="Update" type="submit" class="btn btn-warning" /></form></td>
27+
<td><button type="button" class="btn btn-danger">Delete</button></td>
28+
</tr>
29+
</table>
30+
</div>
31+
</div>
32+
<div class="row">
33+
<a href="#/CreatePonctualEvent" class="btn btn-success btn-lg">Create a new ponctual event!</a>
2834
</div>
29-
3035
</div>
3136

3237
<!-- Modal -->

Diff for: Zenergy/Zenergy/Pages/ponctualEventCreation.html

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<h1>Create a new ponctual event</h1>
2+
<div class="container " ng-controller="ponctualEventCreationPageController">
3+
<div class="row">
4+
<!--
5+
<div name="formRegistration" class="col-md-3 col-lg-offset-4">
6+
<form ng-submit="register()">
7+
8+
<div class="form-group">
9+
<input type="email" class="form-control" ng-model="user.mail" placeholder="Event name" required>
10+
</div>
11+
12+
<div class="form-group">
13+
<input type="password" id="password" name="user.password" class="form-control" ng-model="user.password" placeholder="Password" required>
14+
</div>
15+
16+
<div class="form-group">
17+
<input type="password" id="passwordBis" name="passwordBis" class="form-control" ng-model="user.passwordBis" placeholder="Password Confirmation" required samepassword="password">
18+
</div>
19+
<p class="text-danger" ng-if="passNotMatch">Passwords don't match</p>
20+
21+
<div class="form-group">
22+
<input type="text" class="form-control" ng-model="user.firstName" placeholder="Firstname">
23+
</div>
24+
25+
<div class="form-group">
26+
<input type="text" class="form-control" ng-model="user.lastName" placeholder="Lastname">
27+
</div>
28+
29+
<div class="form-group">
30+
<input type="text" class="form-control" ng-model="user.adr1" placeholder="Address">
31+
</div>
32+
33+
<div class="form-group">
34+
<input type="text" class="form-control" ng-model="user.adr2" placeholder="Rest of the address ">
35+
</div>
36+
37+
<div class="form-group">
38+
<input type="text" class="form-control" ng-model="user.pc" placeholder="Postal Code ">
39+
</div>
40+
41+
<div class="form-group">
42+
<input type="text" class="form-control" ng-model="user.town" placeholder="Town ">
43+
</div>
44+
45+
<div class="form-group">
46+
<input type="text" class="form-control" ng-model="user.phone" placeholder="Phone ">
47+
</div>
48+
49+
<input type="submit" id="submit" value="Sign in" class="btn btn-primary" />
50+
</form>
51+
</div>
52+
-->
53+
</div>
54+
</div>
55+

Diff for: Zenergy/Zenergy/Pages/regularEventCreation.html

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<h1>Create a new Event</h1>
2+
<div class="container " ng-controller="regularEventCreationPageController">
3+
<div class="row">
4+
<!--
5+
<div name="formRegistration" class="col-md-3 col-lg-offset-4">
6+
<form ng-submit="register()">
7+
8+
<div class="form-group">
9+
<input type="email" class="form-control" ng-model="user.mail" placeholder="Event name" required>
10+
</div>
11+
12+
<div class="form-group">
13+
<input type="password" id="password" name="user.password" class="form-control" ng-model="user.password" placeholder="Password" required>
14+
</div>
15+
16+
<div class="form-group">
17+
<input type="password" id="passwordBis" name="passwordBis" class="form-control" ng-model="user.passwordBis" placeholder="Password Confirmation" required samepassword="password">
18+
</div>
19+
<p class="text-danger" ng-if="passNotMatch">Passwords don't match</p>
20+
21+
<div class="form-group">
22+
<input type="text" class="form-control" ng-model="user.firstName" placeholder="Firstname">
23+
</div>
24+
25+
<div class="form-group">
26+
<input type="text" class="form-control" ng-model="user.lastName" placeholder="Lastname">
27+
</div>
28+
29+
<div class="form-group">
30+
<input type="text" class="form-control" ng-model="user.adr1" placeholder="Address">
31+
</div>
32+
33+
<div class="form-group">
34+
<input type="text" class="form-control" ng-model="user.adr2" placeholder="Rest of the address ">
35+
</div>
36+
37+
<div class="form-group">
38+
<input type="text" class="form-control" ng-model="user.pc" placeholder="Postal Code ">
39+
</div>
40+
41+
<div class="form-group">
42+
<input type="text" class="form-control" ng-model="user.town" placeholder="Town ">
43+
</div>
44+
45+
<div class="form-group">
46+
<input type="text" class="form-control" ng-model="user.phone" placeholder="Phone ">
47+
</div>
48+
49+
<input type="submit" id="submit" value="Sign in" class="btn btn-primary" />
50+
</form>
51+
</div>
52+
-->
53+
</div>
54+
</div>
55+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
zenergyApp.controller("ponctualEventCreationPageController", ["$scope", "$http", "tokenService", "$window", "$location", function ($scope, $http, tokenService, $window, $location) {
2+
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+
});
16+
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+
});
30+
31+
$scope.ponctualEvent = {};
32+
33+
}]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
zenergyApp.controller("regularEventCreationPageController", ["$scope", "$http", "tokenService", "$window", "$location", function ($scope, $http, tokenService, $window, $location) {
2+
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+
});
16+
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+
});
30+
31+
$scope.regularEvent = {};
32+
33+
}]);

Diff for: Zenergy/Zenergy/Scripts/Lib/_references.js

318 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)