Пример #1
0
 public static Room MapAsNewEntity(this CreateRoomRequestModel2 model, Hotel hotel)
 {
     return(new Room
     {
         Number = model.Number,
         Hotel = hotel
     });
 }
Пример #2
0
        public async Task <ActionResult <RoomModel> > Post(int hotelId, CreateRoomRequestModel2 model)
        {
            var hotel = await this.context.Hotels.FindAsync(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 { hotelId = hotelId, id = entity.Id }, entity.MapAsModel()));
        }