public int AddProductAttributeValueTag(ProductAttributeValueTag productAttributeValueTag) { _store.ProductAttributeValueTags.Add(productAttributeValueTag); CreateOrChangeEntityLanguage(productAttributeValueTag); _store.SaveChanges(); return productAttributeValueTag.Id; }
public ActionResult Edit(ProductAttributeValueTag model) { _repository.LangId = CurrentLangId; var productAttributeValueTag = _repository.GetProductAttributeValueTag(model.Id); TryUpdateModel(productAttributeValueTag, new[] { "Title" ,"Name"}); _repository.SaveProductAttributeValueTag(productAttributeValueTag); return RedirectToAction("Index"); }
public ActionResult Create(ProductAttributeValueTag model) { _repository.LangId = CurrentLangId; try { _repository.AddProductAttributeValueTag(model); } catch (Exception ex) { TempData["errorMessage"] = ex.Message; return View(model); } return RedirectToAction("Index"); }
private void CreateOrChangeEntityLanguage(ProductAttributeValueTag cache) { var categoryLang = _store.ProductAttributeValueTagLangs.FirstOrDefault(r => r.ProductAttributeValueTagId == cache.Id && r.LanguageId == LangId); if (categoryLang == null) { var entityLang = new ProductAttributeValueTagLang { ProductAttributeValueTagId = cache.Id, LanguageId = LangId, Title = cache.Title, }; _store.ProductAttributeValueTagLangs.Add(entityLang); } else { categoryLang.Title = cache.Title; } }
public void SaveProductAttributeValueTag(ProductAttributeValueTag productAttributeValueTag) { var cache = _store.ProductAttributeValueTags.Single(c => c.Id == productAttributeValueTag.Id); CreateOrChangeEntityLanguage(cache); _store.SaveChanges(); }