// GET: ProductCategory/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductCategory productCategory = db.ProductCategories.Find(id); if (productCategory == null) { return(HttpNotFound()); } ProductAttributeTemplate productAttributeTemplate = db.ProductAttributeTemplates.FirstOrDefault(pat => pat.categoryID == id); ViewBag.parentCategory = new SelectList(db.ProductCategories, "categoryID", "categoryName", productCategory.parentCategory); ViewBag.attribteValueTypes = db.AttribteValueTypes.ToList(); ViewBag.units = db.Units.ToList(); ViewBag.productAttributeTemplateGroupID = db.ProductAttributeTemplateGroups.Where(p => p.categoryID == id).ToList(); ViewBag.productAttributeTemplates = db.ProductAttributeTemplates.Where(pta => pta.categoryID == id).ToList(); return(View(productCategory)); }
public async Task <Result> Post([FromBody] ProductAttributeTemplateParam model) { var template = new ProductAttributeTemplate { Name = model.Name }; var attributeIds = model.AttributeIds.Distinct(); if (attributeIds.Count() > 0) { var attrIds = await _productAttrRepo .Query(c => attributeIds.Contains(c.Id)) .Select(c => c.Id) .ToListAsync(); foreach (var attrId in attrIds) { template.AddAttribute(attrId); } } _productAttrTempRepo.Add(template); await _productAttrTempRepo.SaveChangesAsync(); return(Result.Ok()); }
public ActionResult CreateAttribueTemplateFormElement() { ProductAttributeTemplate productAttributeTemplate = new ProductAttributeTemplate() { searchable = false }; ViewBag.unitID = new SelectList(db.Units, "unitID", "unitName"); ViewBag.attributeValueTypeID = new SelectList(db.AttribteValueTypes, "attributeValueTypeID", "valueType"); ViewBag.ProductAttributeTemplateGroupID = new SelectList(db.ProductAttributeTemplateGroups, "productAttributeTemplateGroupID", "name"); return(PartialView("~/Views/ProductCategory/_CreateElementAttribute.cshtml", productAttributeTemplate)); }