public ActionResult CreateProductType(ProductType productType) { if (ModelState.IsValid) { var service = new ProductTypeService(); int id = service.Insert(productType); if (id > 0) { SetAlert("Thêm loại sản phẩm thành công!", "success"); return(RedirectToAction("Index", "ProductTypeAdmin")); } else { ModelState.AddModelError("", "Thêm loại sản phẩm thất bại!"); } } return(View("Index")); }
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)); }
/// <summary> /// /// </summary> /// <param name="portalid"></param> /// <param name="prodtype"></param> /// <param name="connString"></param> /// <returns></returns> private static int ZnodeProductTypeInsert(int portalid, string prodtypeName, string connString) { int prodtypeid = 0; try { SqlConnection conn = new SqlConnection(connString); SqlCommand SKUCMD = new SqlCommand("ZNODE_NT_ZNodeProductType_Find", conn); SKUCMD.CommandType = CommandType.StoredProcedure; SqlParameter param; param = new SqlParameter("@portalid", SqlDbType.Int); param.Value = portalid; SKUCMD.Parameters.Add(param); param = new SqlParameter("@Name", SqlDbType.VarChar); param.Value = prodtypeName; SKUCMD.Parameters.Add(param); conn.Open(); SqlDataReader dr = SKUCMD.ExecuteReader(); if (dr.HasRows) { if (dr.Read()) { prodtypeid = Convert.ToInt32(dr["ProducttypeId"]); } } else { ProductTypeService prodTypeServ = new ProductTypeService(); ProductType prodType = new ProductType(); prodType.PortalId = portalid; prodType.Name = prodtypeName; prodTypeServ.Insert(prodType); prodtypeid = prodType.ProductTypeId; } conn.Close(); return prodtypeid; } catch (Exception) { return 0; } }