// 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;
            }
            
        }
Esempio n. 2
0
        public static Module CreateModel(ModuleViewModel moduleViewModel)
        {
            Module module = new Module()
            {
                Active = moduleViewModel.ModuleActive,
                Name = moduleViewModel.Name,
                Orden = moduleViewModel.Orden,
                Image = moduleViewModel.Image,
                Pending = moduleViewModel.Pending,
                Prefix = moduleViewModel.Prefix,
                Comment = moduleViewModel.Comment
            };

            module.Translation = new Translation()
            {
                Spanish = moduleViewModel.Spanish,
                English = moduleViewModel.English,
                French = moduleViewModel.French,
                German = moduleViewModel.German,
                Language5 = moduleViewModel.Language5,
                Language6 = moduleViewModel.Language6,
                Language7 = moduleViewModel.Language7,
                Language8 = moduleViewModel.Language8,
                Active = moduleViewModel.TranslationActive,
            };
            module.Catalogues = new List<Catalog>();

            module.Catalogues.Add(new Catalog()
            {
                CatalogId = moduleViewModel.CatalogId,
                Name = moduleViewModel.CatalogName
            });

         
            return module;
        }