public static List<ActiveHotelCatalogue> CreateModel(ActiveHotelCataloguesViewModel hotelCatalogViewModel) { List<ActiveHotelCatalogue> hotelCatalogues = new List<ActiveHotelCatalogue>(); foreach (int catalogid in hotelCatalogViewModel.CataloguesIds) { hotelCatalogues.Add(new ActiveHotelCatalogue() { IdHotel = hotelCatalogViewModel.HotelId, IdCatalogue = catalogid, Active = true }); } return hotelCatalogues; }
public IHttpActionResult PostHotelsWithCatalogues(ActiveHotelCataloguesViewModel hotelsCataloguesViewModel) { if (!ModelState.IsValid) { return BadRequest(ModelState); } ActiveHotelCatalogRepository hotelCatalogRepo = new ActiveHotelCatalogRepository(new MyRoomDbContext()); List<ActiveHotelCatalogue> hotelCatalogues = ActiveHotelCatalogMapper.CreateModel(hotelsCataloguesViewModel); hotelCatalogRepo.InsertActiveHotelCatalogues(hotelCatalogues, hotelsCataloguesViewModel.HotelId); return Ok("Catalogues Assigned to hotels"); }