Esempio n. 1
0
 public static Room MapAsNewEntity(this CreateRoomRequestModel model, Hotel hotel)
 {
     return(new Room
     {
         Number = model.Number,
         Hotel = hotel
     });
 }
        public async Task <ActionResult <RoomModel> > Post(CreateRoomRequestModel model)
        {
            var hotel = await this.context.Hotels.FindAsync(model.HotelId);

            if (hotel == null)
            {
                return(this.NotFound());
            }

            var entity = model.MapAsNewEntity(hotel);

            this.context.Rooms.Add(entity);
            await this.context.SaveChangesAsync();

            return(this.CreatedAtAction("Get", new { id = entity.Id }, entity.MapAsModel()));
        }
Esempio n. 3
0
        public async Task <IActionResult> CreateRoom(CreateRoomRequestModel createRoomRequestModel)
        {
            await this.roomService.CreateRoomAsync(createRoomRequestModel);

            return(this.Ok($"Room {createRoomRequestModel.Number} successfully created."));
        }