Skip to content

Commit c4c3500

Browse files
committed
Merge branch 'roomManagement-feature'
2 parents eca6895 + cdf2aae commit c4c3500

File tree

6 files changed

+249
-1
lines changed

6 files changed

+249
-1
lines changed

Diff for: Zenergy/Zenergy/Controllers/AccountController.cs

+11
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public UserInfoViewModel GetUserInfo()
7373
};
7474
}
7575

76+
77+
/// <summary>
78+
/// Log out the current user.
79+
/// </summary>
80+
/// <returns></returns>
7681
// POST api/Account/Logout
7782
[Route("Logout")]
7883
public IHttpActionResult Logout()
@@ -325,6 +330,12 @@ public IEnumerable<ExternalLoginViewModel> GetExternalLogins(string returnUrl, b
325330
return logins;
326331
}
327332

333+
334+
/// <summary>
335+
/// Login the user.
336+
/// </summary>
337+
/// <param name="model"></param>
338+
/// <returns></returns>
328339
// POST api/Account/Register
329340
[AllowAnonymous]
330341
[Route("Register")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
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+
14+
namespace Zenergy.Controllers.ApiControllers
15+
{
16+
public class roomContentsController : ApiController
17+
{
18+
private ZenergyContext db = new ZenergyContext();
19+
20+
21+
/// <summary>
22+
/// Get all roomContents from the database.
23+
/// </summary>
24+
/// <returns></returns>
25+
// GET: api/roomContents
26+
public IQueryable<roomContent> GetroomContent()
27+
{
28+
return db.roomContent;
29+
}
30+
/// <summary>
31+
/// Get the roomContent by id
32+
/// </summary>
33+
/// <param name="id"></param>
34+
/// <returns></returns>
35+
// GET: api/roomContents/5
36+
[ResponseType(typeof(roomContent))]
37+
public async Task<IHttpActionResult> GetroomContent(int id)
38+
{
39+
roomContent roomContent = await db.roomContent.FindAsync(id);
40+
if (roomContent == null)
41+
{
42+
return NotFound();
43+
}
44+
45+
return Ok(roomContent);
46+
}
47+
48+
49+
/// <summary>
50+
/// Edit the roomContent which primary key is (roomId,accessoryId) with roomContent parameter.
51+
/// </summary>
52+
/// <param name="roomId"></param>
53+
/// <param name="accessoryId"></param>
54+
/// <param name="roomContent"></param>
55+
/// <returns></returns>
56+
// PUT: api/roomContents/5
57+
[ResponseType(typeof(void))]
58+
public async Task<IHttpActionResult> PutroomContent(int roomId,int accessoryId, roomContent roomContent)
59+
{
60+
if (!ModelState.IsValid)
61+
{
62+
return BadRequest(ModelState);
63+
}
64+
65+
if (roomId != roomContent.roomId || accessoryId != roomContent.accessoryId)
66+
{
67+
return BadRequest();
68+
}
69+
70+
db.Entry(roomContent).State = EntityState.Modified;
71+
72+
try
73+
{
74+
await db.SaveChangesAsync();
75+
}
76+
catch (DbUpdateConcurrencyException)
77+
{
78+
if (!roomContentExists(roomId, accessoryId))
79+
{
80+
return NotFound();
81+
}
82+
else
83+
{
84+
throw;
85+
}
86+
}
87+
88+
return StatusCode(HttpStatusCode.NoContent);
89+
}
90+
91+
92+
/// <summary>
93+
/// Create the roomContent in the database.
94+
/// </summary>
95+
/// <param name="roomContent"></param>
96+
/// <returns></returns>
97+
// POST: api/roomContents
98+
[ResponseType(typeof(roomContent))]
99+
public async Task<IHttpActionResult> PostroomContent(roomContent roomContent)
100+
{
101+
if (!ModelState.IsValid)
102+
{
103+
return BadRequest(ModelState);
104+
}
105+
106+
db.roomContent.Add(roomContent);
107+
108+
try
109+
{
110+
await db.SaveChangesAsync();
111+
}
112+
catch (DbUpdateException)
113+
{
114+
if (roomContentExists(roomContent.roomId, roomContent.accessoryId))
115+
{
116+
return Conflict();
117+
}
118+
else
119+
{
120+
throw;
121+
}
122+
}
123+
124+
return CreatedAtRoute("DefaultApi", new { id = roomContent.roomId }, roomContent);
125+
}
126+
127+
128+
/// <summary>
129+
/// Delete the roomContent which primary key is (roomId,accessory).
130+
/// </summary>
131+
/// <param name="roomId"></param>
132+
/// <param name="accessoryId"></param>
133+
/// <returns></returns>
134+
// DELETE: api/roomContents?roomId=2&accessoryId=1
135+
[ResponseType(typeof(roomContent))]
136+
public async Task<IHttpActionResult> DeleteroomContent(int roomId, int accessoryId)
137+
{
138+
roomContent roomContent = await db.roomContent.Where(rc => rc.roomId == roomId & rc.accessoryId == accessoryId).FirstAsync();
139+
if (roomContent == null)
140+
{
141+
return NotFound();
142+
}
143+
144+
db.roomContent.Remove(roomContent);
145+
await db.SaveChangesAsync();
146+
147+
return Ok(roomContent);
148+
}
149+
150+
protected override void Dispose(bool disposing)
151+
{
152+
if (disposing)
153+
{
154+
db.Dispose();
155+
}
156+
base.Dispose(disposing);
157+
}
158+
159+
private bool roomContentExists(int roomId, int accessoryId)
160+
{
161+
return db.roomContent.Count(e => e.roomId == roomId && e.accessoryId == accessoryId) > 0;
162+
}
163+
}
164+
}

Diff for: Zenergy/Zenergy/Controllers/ApiControllers/roomsController.cs

+30
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,23 @@ public class roomsController : ApiController
1919
{
2020
private ZenergyContext db = new ZenergyContext();
2121

22+
23+
/// <summary>
24+
/// Get all the room from the database.
25+
/// </summary>
26+
/// <returns></returns>
2227
// GET: api/rooms
2328
public IQueryable<room> Getroom()
2429
{
2530
return db.room;
2631
}
2732

33+
34+
/// <summary>
35+
/// Get room by id.
36+
/// </summary>
37+
/// <param name="id"></param>
38+
/// <returns></returns>
2839
// GET: api/rooms/5
2940
[ResponseType(typeof(room))]
3041
public async Task<IHttpActionResult> Getroom(int id)
@@ -38,6 +49,13 @@ public async Task<IHttpActionResult> Getroom(int id)
3849
return Ok(room);
3950
}
4051

52+
53+
/// <summary>
54+
/// Edit the room which primary key is id using the room parameter.
55+
/// </summary>
56+
/// <param name="id"></param>
57+
/// <param name="room"></param>
58+
/// <returns></returns>
4159
// PUT: api/rooms/5
4260
[ResponseType(typeof(void))]
4361
public async Task<IHttpActionResult> Putroom(int id, room room)
@@ -73,6 +91,12 @@ public async Task<IHttpActionResult> Putroom(int id, room room)
7391
return StatusCode(HttpStatusCode.NoContent);
7492
}
7593

94+
95+
/// <summary>
96+
/// Create room in the database.
97+
/// </summary>
98+
/// <param name="room"></param>
99+
/// <returns></returns>
76100
// POST: api/rooms
77101
[ResponseType(typeof(room))]
78102
public async Task<IHttpActionResult> Postroom(room room)
@@ -88,6 +112,12 @@ public async Task<IHttpActionResult> Postroom(room room)
88112
return CreatedAtRoute("DefaultApi", new { id = room.roomId }, room);
89113
}
90114

115+
116+
/// <summary>
117+
/// Delete the room by id.
118+
/// </summary>
119+
/// <param name="id"></param>
120+
/// <returns></returns>
91121
// DELETE: api/rooms/5
92122
[ResponseType(typeof(room))]
93123
public async Task<IHttpActionResult> Deleteroom(int id)

Diff for: Zenergy/Zenergy/Controllers/ApiControllers/usersController.cs

+36-1
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,24 @@ public usersController()
2424
userServices = new UserServices(db);
2525
}
2626

27+
28+
/// <summary>
29+
/// Get all users.
30+
/// </summary>
31+
/// <returns></returns>
2732
// GET: api/users
2833
[Authorize]
2934
public IQueryable<user> Getuser()
3035
{
3136
return db.user;
3237
}
3338

39+
40+
/// <summary>
41+
/// Get user by id.
42+
/// </summary>
43+
/// <param name="id"></param>
44+
/// <returns></returns>
3445
// GET: api/users/5
3546
[ResponseType(typeof(user))]
3647
public async Task<IHttpActionResult> Getuser(int id)
@@ -44,8 +55,13 @@ public async Task<IHttpActionResult> Getuser(int id)
4455
return Ok(user);
4556
}
4657

58+
59+
/// <summary>
60+
/// Return all the users of a role.
61+
/// </summary>
62+
/// <param name="role"></param>
63+
/// <returns></returns>
4764
// GET: api/users/findByRole
48-
// Return all the users of a role
4965
[Route("api/users/findByRole")]
5066
[HttpGet]
5167
[ResponseType(typeof(user[]))]
@@ -76,6 +92,13 @@ public async Task<IHttpActionResult> FindByRole(string role) {
7692
return Ok(users);
7793
}
7894

95+
96+
/// <summary>
97+
/// Edit user.
98+
/// </summary>
99+
/// <param name="id"></param>
100+
/// <param name="user"></param>
101+
/// <returns></returns>
79102
// PUT: api/users/5
80103
[ResponseType(typeof(void))]
81104
public async Task<IHttpActionResult> Putuser(int id, user user)
@@ -111,6 +134,12 @@ public async Task<IHttpActionResult> Putuser(int id, user user)
111134
return StatusCode(HttpStatusCode.NoContent);
112135
}
113136

137+
138+
/// <summary>
139+
/// Create user.
140+
/// </summary>
141+
/// <param name="user"></param>
142+
/// <returns></returns>
114143
// POST: api/users
115144
[ResponseType(typeof(user))]
116145
public async Task<IHttpActionResult> Postuser(user user)
@@ -126,6 +155,12 @@ public async Task<IHttpActionResult> Postuser(user user)
126155
return CreatedAtRoute("DefaultApi", new { id = user.userId }, user);
127156
}
128157

158+
159+
/// <summary>
160+
/// Delete user by id.
161+
/// </summary>
162+
/// <param name="id"></param>
163+
/// <returns></returns>
129164
// DELETE: api/users/5
130165
[ResponseType(typeof(user))]
131166
public async Task<IHttpActionResult> Deleteuser(int id)

Diff for: Zenergy/Zenergy/Services/UserServices.cs

+7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ public async Task<user[]> getMembers()
4141
return await db.user.SqlQuery("SELECT usr.* FROM [user] usr INNER JOIN [member] role ON usr.userId = role.userId").ToArrayAsync();
4242
}
4343

44+
45+
/// <summary>
46+
/// Find user by mail and password.
47+
/// </summary>
48+
/// <param name="userMail"></param>
49+
/// <param name="userPass"></param>
50+
/// <returns></returns>
4451
public async Task<user> findByMailAndPassword(string userMail, string userPass)
4552
{
4653
try

Diff for: Zenergy/Zenergy/Zenergy.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@
176176
</Reference>
177177
</ItemGroup>
178178
<ItemGroup>
179+
<Compile Include="Controllers\ApiControllers\roomContentsController.cs" />
179180
<Compile Include="Controllers\ApiControllers\roomsController.cs" />
180181
<Compile Include="Controllers\ApiControllers\usersController.cs" />
181182
<Compile Include="Controllers\HomeController.cs" />

0 commit comments

Comments
 (0)