public ActionResult OnCreate(ProductTypeModels productType) { if (ModelState.IsValid) { productType.ImageUrl = productType.Image != null? productType.Image.Upload() : productType.ImageUrl; productType.ImageBannerUrl = productType.ImageBanner != null? productType.ImageBanner.Upload() : productType.ImageBannerUrl; var result = ProductTypeService.Insert( productType.Name, productType.ParentId, productType.Icon, productType.Description, productType.ImageUrl, productType.ImageBannerUrl, productType.Number, productType.CreatedDate, productType.Status, productType.IsHome ); if (result == Result.Exists) { ModelState.AddModelError("", string.Format("Loại sản phẩm '{productType.Name}' đã tồn tại trên hệ thống.")); ViewBag.ListCategory = BuildListCategory(); return(View("Create", productType)); } SetFlashMessage(string.Format("Thêm loại sản phẩm '{productType.Name}' thành công.")); if (productType.SaveList) { return(RedirectToAction("Index")); } ViewBag.ListCategory = BuildListCategory(); ModelState.Clear(); return(View("Create", productType.ResetValue())); } ViewBag.ListCategory = BuildListCategory(); return(View("Create", productType)); }