public ActionResult OnCreate(ProductBrandModels brand) { if (ModelState.IsValid) { brand.ImageUrl = brand.Image != null? brand.Image.Upload() : brand.ImageUrl; var result = ProductBrandService.Insert ( brand.Name, brand.CategoryId, brand.ImageUrl, brand.Status ); if (result == Result.Exists) { ModelState.AddModelError("", $"Tên thương hiệu '{brand.Name}' đã tồn tại trên hệ thống."); ViewBag.ListState = DataHelper.ListEnumType <StateEnum>(); ViewBag.ListCategory = GetListMutilCategoryItem(); return(View("Create", brand)); } SetFlashMessage($"Thêm thương hiệu '{brand.Name}' thành công."); if (brand.SaveList) { return(RedirectToAction("Index")); } ViewBag.ListState = DataHelper.ListEnumType <StateEnum>(); ViewBag.ListCategory = GetListMutilCategoryItem(); ModelState.Clear(); return(View("Create", brand.ResetValue())); } ViewBag.ListState = DataHelper.ListEnumType <StateEnum>(); ViewBag.ListCategory = GetListMutilCategoryItem(); return(View("Create", brand)); }
public ActionResult OnEdit(ProductBrandModels brand) { if (ModelState.IsValid) { brand.ImageUrl = brand.Image != null? brand.Image.Upload() : brand.ImageUrl.ToImageOriginalPath(); var result = ProductBrandService.Update( brand.Id, brand.Name, brand.CategoryId, brand.ImageUrl, brand.Status); if (result == Result.NotExists) { ModelState.AddModelError("", "Thương hiệu không tồn tại trên hệ thống."); ViewBag.ListState = DataHelper.ListEnumType <StateEnum>(); ViewBag.ListCategory = GetListMutilCategoryItem(); return(View("Edit", brand)); } SetFlashMessage($"Cập nhật thương hiệu '{brand.Name}' thành công."); if (brand.SaveList) { return(RedirectToAction("Index")); } ViewBag.ListState = DataHelper.ListEnumType <StateEnum>(); ViewBag.ListCategory = GetListMutilCategoryItem(); return(View("Edit", brand)); } ViewBag.ListState = DataHelper.ListEnumType <StateEnum>(); ViewBag.ListCategory = GetListMutilCategoryItem(); return(View("Edit", brand)); }
public ActionResult Create() { ViewBag.ListState = DataHelper.ListEnumType <StateEnum>(); ViewBag.ListCategory = GetListMutilCategoryItem(); var brand = new ProductBrandModels(); return(View("Create", brand)); }
public ActionResult Edit(int id) { var brand = ProductBrandService.Find(id); if (brand == null) { return(RedirectToAction("Index")); } ViewBag.ListState = DataHelper.ListEnumType <StateEnum>(); ViewBag.ListCategory = GetListMutilCategoryItem(); var data = new ProductBrandModels { Id = brand.id, CategoryId = brand.category_default, ImageUrl = brand.image, Name = brand.name, Status = (byte)brand.status }; return(View("Edit", data)); }