public IHttpActionResult PutRoomType(int id, RoomTypeViewModel roomTypeViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != roomTypeViewModel.RoomTypeId) { return(BadRequest()); } RoomType roomType = ViewModelMapper.ToModelRoomTypes(roomTypeViewModel); db.Entry(roomType).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!RoomTypeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PostRoomType(RoomTypeViewModel roomTypeViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } RoomType roomType = ViewModelMapper.ToModelRoomTypes(roomTypeViewModel); db.RoomTypes.Add(roomType); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = roomType.RoomTypeId }, ViewModelMapper.ToViewModelRoomTypes(roomType))); }