public IHttpActionResult PostAssignHotelElements(AssignHotelCatalogViewModel assignHotelCatalogViewModel) { if (!ModelState.IsValid) { return BadRequest(ModelState); } ActiveHotelProductRepository activeHotelProductRepo = new ActiveHotelProductRepository(new MyRoomDbContext()); List<ActiveHotelProduct> products = ActiveHotelProductsMapper.CreateModel(assignHotelCatalogViewModel); ActiveHotelCategoryRepository activeHotelCategoryRepo = new ActiveHotelCategoryRepository(new MyRoomDbContext()); List<ActiveHotelCategory> categories = ActiveHotelCategoriesMapper.CreateModel(assignHotelCatalogViewModel); ActiveHotelModuleRepository activeHotelModuleRepo = new ActiveHotelModuleRepository(new MyRoomDbContext()); List<ActiveHotelModule> modules = ActiveHotelModulesMapper.CreateModel(assignHotelCatalogViewModel); try { activeHotelProductRepo.InsertActiveHotelProduct(products, assignHotelCatalogViewModel.HotelId); activeHotelCategoryRepo.InsertActiveHotelCategory(categories, assignHotelCatalogViewModel.HotelId, true); activeHotelModuleRepo.InsertActiveHotelModule(modules, assignHotelCatalogViewModel.HotelId, true); return Ok("Elements Assigned to hotels"); } catch (Exception ex) { throw ex; } }
// POST: api/modules public IHttpActionResult Post(ModuleViewModel moduleViewModel) { if (!ModelState.IsValid) { return BadRequest(ModelState); } try { Module module = ModuleMapper.CreateModel(moduleViewModel); moduleRepo.CatalogStateUnchange(module); moduleRepo.Insert(module); //busco hotel con el catalogo seleccionado ActiveHotelCatalogRepository hotelCatalog = new ActiveHotelCatalogRepository(new MyRoomDbContext()); int hotelId = hotelCatalog.GetByCatalogId(moduleViewModel.CatalogId); if (hotelId > 0) { //inserto categorias a hotel relacionado ActiveHotelModuleRepository activeHotelModuleRepo = new ActiveHotelModuleRepository(new MyRoomDbContext()); List<ActiveHotelModule> hotelModules = new List<ActiveHotelModule>(); hotelModules.Add(new ActiveHotelModule() { IdModule = module.ModuleId, IdHotel = hotelId }); activeHotelModuleRepo.InsertActiveHotelModule(hotelModules, hotelId); } return Ok(module.ModuleId); } catch (Exception ex) { throw ex; } }