public ActionResult Create(ProductAttribute model) { _repository.LangId = CurrentLangId; try { model.Id = 0; var productAttibute = new ProductAttribute() { ExternalId = model.ExternalId, Title = model.Title, UnitTitle = model.UnitTitle, IsStatic = model.IsStatic, IsPublic = model.IsPublic, DisplayOnPreview = model.DisplayOnPreview, IsFilterable = model.IsFilterable, SortOrder = model.SortOrder }; _repository.AddProductAttribute(productAttibute); Cache.Default.Clear(); } catch (Exception ex) { TempData["errorMessage"] = ex.Message; return View(model); } return RedirectToAction("Index"); }
private void CreateOrChangeEntityLanguage(ProductAttribute cache) { var categoryLang = _store.ProductAttributeLangs.FirstOrDefault(r => r.ProductAttributeId == cache.Id && r.LanguageId == LangId); if (categoryLang == null) { var entityLang = new ProductAttributeLang { ProductAttributeId = cache.Id, LanguageId = LangId, Title = cache.Title, UnitTitle = cache.UnitTitle, }; _store.ProductAttributeLangs.Add(entityLang); } else { categoryLang.Title = cache.Title; categoryLang.UnitTitle = cache.UnitTitle; } }
public void SaveProductAttribute(ProductAttribute productAttribute) { var cache = _store.ProductAttributes.Single(c => c.Id == productAttribute.Id); //cache.UnitTitle = productAttribute.UnitTitle; //cache.SortOrder = productAttribute.SortOrder; //cache.Title = productAttribute.Title; CreateOrChangeEntityLanguage(cache); _store.SaveChanges(); }
public int AddProductAttribute(ProductAttribute productAttribute) { _store.ProductAttributes.Add(productAttribute); CreateOrChangeEntityLanguage(productAttribute); _store.SaveChanges(); return productAttribute.Id; }
public ActionResult Edit(ProductAttribute model) { _repository.LangId = CurrentLangId; try { var productAttribute = _repository.GetProductAttribute(model.Id); TryUpdateModel(productAttribute, new[] { "Title", "ExternalId", "UnitTitle", "IsStatic", "IsPublic", "DisplayOnPreview", "IsFilterable", "SortOrder" }); _repository.SaveProductAttribute(productAttribute); Cache.Default.Clear(); } catch (Exception ex) { TempData["errorMessage"] = ex.Message; return View(model); } return RedirectToAction("Index"); }