// GET: odata/Catalogues(5) // // [EnableQuery(PageSize = 10, AllowedQueryOptions = AllowedQueryOptions.All)] // public SingleResult<Catalog> CatalogComplex() // { // return null; // //return _genericRepository.GetStructureComplete(1); //// return SingleResult.Create(_genericRepository.Context.Catalogues.Where(catalogues => catalogues.CatalogId == id)); // } // PUT: api/Catalogues public async Task<IHttpActionResult> PutCatalogues(Catalog catalog) { if (!ModelState.IsValid) { return BadRequest(ModelState); } try { await catalogRepository.EditAsync(catalog); return Ok("Catalog Updated"); } catch (Exception ex) { if (!CataloguesExists(catalog.CatalogId)) { return NotFound(); } else { throw; } } }
public string CreateWithOutProducts(Catalog cata, bool activemod, bool activecategory, int hotelId = 0, string userId = "") { IList<ModuleCompositeViewModel> modules = new List<ModuleCompositeViewModel>(); foreach (Module m in cata.Modules) { ModuleCompositeViewModel moduleVm = Helper.ConvertModuleToViewModel(m, activemod); modules.Add(moduleVm); //if (!string.IsNullOrEmpty(userId)) //{ // if (activemod) // { // var relUsers = from r in m.RelUserModule // select r; // moduleVm.IsChecked = m.RelUserModule..Contains() // ( new RelUserModule() { Id = IdModule = m.ModuleId, IdUser=userId, ReadOnly=null, ReadWrite=null}); // moduleVm.ActiveCheckbox = true; // } //} foreach (Category p in m.Categories) { if (moduleVm.Children == null) moduleVm.Children = new List<CategoryCompositeViewModel>(); CategoryCompositeViewModel category = Helper.ConvertCategoryToViewModel(p); if (activecategory) { category.IsChecked = p.ActiveHotelCategory.Contains(new ActiveHotelCategory() { IdCategory = p.CategoryId, IdHotel = hotelId, Active = true }); category.ActiveCheckbox = true; } moduleVm.Children.Add(category); CreateSubCategories(category, false, activecategory, hotelId); } } string json = ""; try { json = JsonConvert.SerializeObject(modules, Formatting.Indented, new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects, ReferenceLoopHandling = ReferenceLoopHandling.Serialize }); json = json.Replace("Children", "children"); } catch (Exception ex) { throw ex; } return json; }
public static CatalogCompositeViewModel ConvertCatalogToViewModel(Catalog catalog) { CatalogCompositeViewModel moduleCompositeViewModel = new CatalogCompositeViewModel() { CatalogId = catalog.CatalogId, Name = catalog.Name }; return moduleCompositeViewModel; }
public string CreateWithProducts(Catalog cata, bool activemod, bool activecategory, int hotelId = 0) { IList<ModuleCompositeViewModel> modules = new List<ModuleCompositeViewModel>(); foreach (Module m in cata.Modules) { ModuleCompositeViewModel moduleVm = Helper.ConvertModuleToViewModel(m, activemod); modules.Add(moduleVm); moduleVm.ActiveCheckbox = activemod; m.ActiveHotelModule.ForEach(delegate(ActiveHotelModule hotelModule) { if (hotelModule.IdHotel == hotelId && hotelModule.IdModule == m.ModuleId) { moduleVm.IsChecked = true; } }); foreach (Category p in m.Categories) { if (moduleVm.Children == null) moduleVm.Children = new List<CategoryCompositeViewModel>(); CategoryCompositeViewModel category = Helper.ConvertCategoryToViewModel(p); // category.Products = new List<ProductCompositeViewModel>(); category.Children = new List<ICatalogChildren>(); if (activecategory) { p.ActiveHotelCategory.ForEach(delegate(ActiveHotelCategory hotelCategory) { if (hotelCategory.IdHotel == hotelId && hotelCategory.IdCategory == p.CategoryId) { category.IsChecked = true; } }); category.ActiveCheckbox = true; } foreach (CategoryProduct cp in p.CategoryProducts) { Product product = productRepo.GetById(cp.IdProduct); ProductCompositeViewModel productVm = new ProductCompositeViewModel() { ProductId = product.Id, text = product.Name, ActiveCheckbox = true, }; product.ActiveHotelProduct.ForEach(delegate(ActiveHotelProduct activeProduct) { if (activeProduct.IdProduct == product.Id) productVm.IsChecked = true; }); category.Children.Add(productVm); } moduleVm.Children.Add(category); CreateSubCategories(category, true, activecategory, hotelId); } } string json = ""; try { json = JsonConvert.SerializeObject(modules, Formatting.Indented, new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects, ReferenceLoopHandling = ReferenceLoopHandling.Serialize }); json = json.Replace("Children", "children").Replace("Products", "children"); } catch (Exception ex) { throw ex; } return json; }
//public async Task<IHttpActionResult> GetStructureCatalogues(Catalog catalog) //{ //} // POST: api/Catalogues public IHttpActionResult PostCatalogues(Catalog catalog) { if (!ModelState.IsValid) { return BadRequest(ModelState); } try { catalogRepository.Insert(catalog); int catalogid = catalog.CatalogId; if (catalog.Image!="/img/no-image.jpg") catalog.Image = string.Format("{0}/{1}/{2}", ConfigurationManager.AppSettings["UploadImages"], catalogid , catalog.Image); catalogRepository.Edit(catalog); //this.CreateStructureDirectories(catalogid); return Ok(catalogid); } catch (Exception ex) { throw ex; } }
//public async Task<IHttpActionResult> GetStructureCatalogues(Catalog catalog) //{ //} // POST: api/Catalogues //[Authorize(Roles = "Admins")] public IHttpActionResult PostCatalogues(Catalog catalog) { if (!ModelState.IsValid) { return BadRequest(ModelState); } try { catalogRepository.Insert(catalog); int catalogid = catalog.CatalogId; if (catalog.Image!="/img/no-image.jpg") catalog.Image = string.Format("{0}/{1}/{2}", ConfigurationManager.AppSettings["UploadImages"], catalogid , catalog.Image); //Agregar el Catalog en Rel_User_Catalogue con los Id de user y catalog //UserInformation user1 = new UserInformation(new MyRoomDbContext()); //user1.InformationUser(HttpContext.Current.User.Identity.Name); //var Id = user1.IdUser; //var rol = user1.Rol; //catalog.RelUserCatalogue.Add(new RelUserCatalogue() //{ // IdCatalogue = catalog.CatalogId, // IdUser = Id //}); catalogRepository.Edit(catalog); //this.CreateStructureDirectories(catalogid); return Ok(catalogid); } catch (Exception ex) { throw ex; } }