public static Room MapAsNewEntity(this CreateRoomResource model, Hotel hotel) { return(new Room { Number = model.Number, Hotel = hotel }); }
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())); }