Esempio n. 1
0
 public static Room MapAsNewEntity(this CreateRoomResource model, Hotel hotel)
 {
     return(new Room
     {
         Number = model.Number,
         Hotel = hotel
     });
 }
Esempio n. 2
0
        public async Task <ActionResult <RoomResource> > Post(int hotelId, CreateRoomResource 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, id = entity.Id }, entity.MapAsResource()));
        }