public ActionResult ProductAttributeFormPartialView(int?id) { if (id == null) { id = 0; } var modeldata = productCategoriesRepository.getProductAttributeById(id.Value); if (modeldata == null) { ProductAttributeModal objresult = new ProductAttributeModal(); BindProductCategoryModel(objresult); return(View(objresult)); } var result = new ProductAttributeModal() { AttributeId = modeldata.AttributeId, ProdCatId = modeldata.ProdCatId, AttributeName = modeldata.AttributeName }; BindProductCategoryModel(result); result = result == null ? new ProductAttributeModal() : result; return(View(result)); }
private void InsertUpdateProductAttribute(ProductAttributeModal model) { try { ProductAttribute productAttribute = new ProductAttribute(); productAttribute.AttributeName = model.AttributeName; productAttribute.ProdCatId = model.ProdCatId; productAttribute.AttributeId = model.AttributeId; var result = productCategoriesRepository.InsertUpdateProductAttribute(productAttribute); } catch (Exception ex) { throw ex; } }
private void BindProductCategoryModel(ProductAttributeModal model) { model.ProductCategoryList = productCategoriesRepository.GetProductCategoryInfo(null, null, null, 1, int.MaxValue) .Select(x => new SelectListItem() { Text = x.CategoryName, Value = x.ProdCatId.ToString() }).ToList(); model.ProductCategoryList.Insert(0, new SelectListItem() { Text = "Select", Value = "" }); }
public ActionResult SaveProductAttribute(ProductAttributeModal model) { List <string> messages = new List <string>(); bool responseStatus = true; if (!ModelState.IsValid) { responseStatus = false; messages = ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage) .ToList(); } try { if (responseStatus && model.ProdCatId > 0 && productCategoriesRepository.getProductCategoryDetilsById(model.ProdCatId) != null) { InsertUpdateProductAttribute(model); responseStatus = true; messages.Add("Product Category data inserted successfully."); } else if (responseStatus) { InsertUpdateProductAttribute(model); responseStatus = true; messages.Add("Product Category data updated successfully."); } } catch (Exception ex) { responseStatus = false; messages.Add("something went wrong, please contact your administrator." + ex.Message); } return(Json(new { messages, responseStatus }, JsonRequestBehavior.AllowGet)); }