public ActionResult CreateAttribute() { var model = new AdminCreateProductAttributeViewModel { AllValueType = GetListValueType(), IsNull = true }; return(View(model)); }
public ActionResult EditAttribute(Guid id) { var attri = _productSevice.GetAttribute(id); if (attri == null) { return(RedirectToAction("Attribute")); } var model = new AdminCreateProductAttributeViewModel { AllValueType = GetListValueType(), Id = attri.Id, LangName = attri.LangName, ValueType = attri.ValueType, IsNull = attri.IsNull, IsShowFindter = attri.IsShowFindter }; if (!attri.ValueOption.IsNullEmpty()) { dynamic json = JsonConvert.DeserializeObject(attri.ValueOption); if (json != null) { model.ValueOptions = new List <string>(); foreach (var it in json) { model.ValueOptions.Add((string)it); } } } if (!attri.ValueFindter.IsNullEmpty()) { dynamic json = JsonConvert.DeserializeObject(attri.ValueFindter); if (json != null) { model.FindterNums = new List <AdminAttributeNumberFindter>(); foreach (dynamic it in json) { model.FindterNums.Add(new AdminAttributeNumberFindter { Name = (string)it.Name }); } } } return(View(model)); }
public ActionResult EditAttribute(AdminCreateProductAttributeViewModel model) { model.AllValueType = GetListValueType(); if (ModelState.IsValid) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { try { var attri = _productSevice.GetAttribute(model.Id); if (attri == null) { return(RedirectToAction("Attribute")); } attri.LangName = model.LangName; attri.ValueType = model.ValueType; attri.IsNull = model.IsNull; attri.IsShowFindter = model.IsShowFindter; attri.ValueFindter = JsonConvert.SerializeObject(model.FindterNums); attri.ValueOption = JsonConvert.SerializeObject(model.ValueOptions); _productSevice.Update(attri); // We use temp data because we are doing a redirect TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = "Thuộc tính sản phẩm được cập nhật thành công!", MessageType = GenericMessages.success }; unitOfWork.Commit(); } catch { unitOfWork.Rollback(); ModelState.AddModelError("", "Có lỗi xảy ra khi cập nhật thông tin!"); } } } return(View(model)); }
public ActionResult CreateAttribute(AdminCreateProductAttributeViewModel model) { model.AllValueType = GetListValueType(); if (ModelState.IsValid) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { try { var productAttribute = new ProductAttribute { LangName = model.LangName, ValueType = model.ValueType, IsNull = model.IsNull, IsShowFindter = model.IsShowFindter, ValueFindter = JsonConvert.SerializeObject(model.FindterNums), ValueOption = JsonConvert.SerializeObject(model.ValueOptions), }; _productSevice.Add(productAttribute); unitOfWork.Commit(); // We use temp data because we are doing a redirect TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = "Thêm thuộc tính sản phẩm thành công", MessageType = GenericMessages.success }; return(RedirectToAction("Attribute")); } catch { unitOfWork.Rollback(); ModelState.AddModelError("", "There was an error creating the ProductAttribute"); } } } return(View(model)); }
public ActionResult EditAttribute(Guid id) { var attri = _productSevice.GetAttribute(id); if (attri == null) { return(RedirectToAction("Attribute")); } var model = new AdminCreateProductAttributeViewModel { AllValueType = GetListValueType(), Id = attri.Id, LangName = attri.LangName, ValueType = attri.ValueType, IsNull = attri.IsNull, }; return(View(model)); }