public ActionResult <RoomResponse> GetById(int id) { var item = db.Rooms.Find(id); if (item == null) { return(NotFound(new ProblemDetails() { Title = $"Room id : {id} not found" })); } return(RoomResponse.FromModel(item)); }
public async Task <ActionResult <RoomResponse> > DeleteAsync(int id) { var item = await db.Rooms.FindAsync(id); if (item == null) { return(NotFound(new ProblemDetails { Title = $"Room id {id} not found" })); } db.Remove(item); await db.SaveChangesAsync(); return(RoomResponse.FromModel(item)); }
public ActionResult <RoomResponse> Create(RoomRequest item) { var itemRoomType = db.RoomTypes.Find(item.RoomType); if (itemRoomType == null) { return(NotFound(new ProblemDetails() { Title = $"RoomType code : {item.RoomType} not found" })); } Room newRoom = item.ToModel(); db.Add(newRoom); db.SaveChanges(); return(CreatedAtAction(nameof(GetById), new { id = newRoom.Id }, RoomResponse.FromModel(newRoom))); }