public int AddProductAttributeStaticValue(ProductAttributeStaticValue productAttributeStaticValue) { _store.ProductAttributeStaticValues.Add(productAttributeStaticValue); CreateOrChangeEntityLanguage(productAttributeStaticValue); _store.SaveChanges(); return productAttributeStaticValue.Id; }
private void CreateOrChangeEntityLanguage(ProductAttributeStaticValue cache) { var categoryLang = _store.ProductAttributeStaticValueLangs.FirstOrDefault(r => r.ProductAttributeStaticValueId == cache.Id && r.LanguageId == LangId); if (categoryLang == null) { var entityLang = new ProductAttributeStaticValueLang { ProductAttributeStaticValueId = cache.Id, LanguageId = LangId, Title = cache.Title, }; _store.ProductAttributeStaticValueLangs.Add(entityLang); } else { categoryLang.Title = cache.Title; } }
public ActionResult Attributes(int productId, FormCollection form, string page) { _repository.LangId = CurrentLangId; var product = _repository.GetProduct(productId); PostCheckboxesData attrData = form.ProcessPostCheckboxesData("attr", "productId"); PostData staticAttrData = form.ProcessPostData("tb", "productId"); product.ProductAttributeValues.Clear(); string searchCriteriaAttributes = ""; foreach (var kvp in attrData) { var attributeValueId = kvp.Key; bool attributeValue = kvp.Value; if (attributeValue) { var productAttributeValue = _repository.GetProductAttributeValue(attributeValueId); searchCriteriaAttributes += productAttributeValue.ProductAttributeId + "-" + attributeValueId + ";"; product.ProductAttributeValues.Add(productAttributeValue); } } foreach (var kvp in staticAttrData) { int attributeId = Convert.ToInt32(kvp.Key); foreach (var value in kvp.Value) { string attributeValue = value.Value; var productAttribute = _repository.GetProductAttribute(attributeId); //productAttribute.ProductAttributeStaticValues.Clear(); ProductAttributeStaticValue productAttributeValue = null; productAttributeValue = _repository.GetProductAttributeStaticValue(productAttribute.Id, product.Id); if (string.IsNullOrEmpty(attributeValue)) { if (productAttributeValue != null) _repository.DeleteProductAttributeStaticValue(productAttributeValue.Id); } else { if (productAttributeValue == null) { productAttributeValue = new ProductAttributeStaticValue { Title = attributeValue, ProductAttribute = productAttribute, ProductId = product.Id }; _repository.AddProductAttributeStaticValue(productAttributeValue); } else { productAttributeValue.Title = attributeValue; _repository.SaveProductAttributeStaticValue(productAttributeValue); } } } } product.SearchCriteriaAttributes = searchCriteriaAttributes; _repository.SaveProduct(product); return !string.IsNullOrEmpty(page) ? RedirectToAction("Index", new { page = page }) : RedirectToAction("Index"); }
public void SaveProductAttributeStaticValue(ProductAttributeStaticValue productAttributeStaticValue) { var cache = _store.ProductAttributeStaticValues.Single(c => c.Id == productAttributeStaticValue.Id); CreateOrChangeEntityLanguage(cache); _store.SaveChanges(); }