public ActionResult HandleFormBrand() { if (Session["admin"] == null) { Response.Redirect("~/Admin2/Home/Login"); } try { String id = Request.Params["id"]; String name = Request.Params["name"]; String fromTo = Request.Params["fromto"]; if (id.Equals("0")) { Brand brand = new Brand(); brand.BrandName = name; brand.FromTo = fromTo; br.InsertBrand(brand); } else { Brand brand = new Brand(); brand.ID = Convert.ToInt32(id); brand.BrandName = name; brand.FromTo = fromTo; br.UpdateBrand(brand); } } catch { } return(View("Brand")); }
public ActionResult UpdateBrand(BrandBO brandModel) { if (ModelState.IsValid) { UserLogin user = (UserLogin)Session[CommonConstants.USER_SESSION]; string errorMessage = ""; bool result = false; brandModel.isdeleted = 0; if (brandModel.id > 0) { //get updatemodel BrandBO newUpdateBO = new BrandBO(); newUpdateBO = BrandModel.GetBrandByID(brandModel.id); if (newUpdateBO == null) { ModelState.AddModelError("", "Brand không tồn tại"); return(View(brandModel)); } newUpdateBO.updateduser = user.UserID.ToString(); newUpdateBO.updateddate = DateTime.Now; newUpdateBO.description = brandModel.description; newUpdateBO.isdeleted = 0; newUpdateBO.keyword = brandModel.keyword; newUpdateBO.logo = brandModel.logo; newUpdateBO.metadescription = brandModel.metadescription; newUpdateBO.metakeyword = brandModel.metakeyword; newUpdateBO.name = brandModel.name; newUpdateBO.seoname = brandModel.seoname; result = BrandModel.UpdateBrand(newUpdateBO, ref errorMessage); SetAlert($"Cập nhật Brand {brandModel.id}-{brandModel.name} thành công", "success"); } else { brandModel.createduser = user.UserID.ToString(); brandModel.createddate = DateTime.Now; result = BrandModel.InsertBrand(brandModel, ref errorMessage); SetAlert($"Thêm Brand {brandModel.name} thành công", "success"); } if (result) { return(RedirectToAction("Brand", "Category")); } else { ModelState.AddModelError("", "Có lỗi xảy ra. Thêm thất bại: " + errorMessage); } } return(View(brandModel)); }