public IHttpActionResult PutRoom(int id, RoomViewModel roomViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != roomViewModel.RoomId) { return(BadRequest()); } Room room = ViewModelMapper.ToModelRooms(roomViewModel); db.Entry(room).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!RoomExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PostRoom(RoomViewModel roomViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Room room = ViewModelMapper.ToModelRooms(roomViewModel); db.Rooms.Add(room); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = room.RoomId }, ViewModelMapper.ToViewModelRooms(room))); }