public ActionResult CategoryAdd(CategoryDTO category) { CategoryBL bl = new CategoryBL(); category.created_by = 0; category.updated_by = 0; bl.InsertData(category); return(RedirectToAction("CategoryAdd")); }
public ActionResult AddCategory(CategoryDTO category) { try { if (ModelState.IsValid) { if (!category.code.Contains(" ")) { int count = categoryBL.CountData(new CategoryDTO() { code_key = category.code }); if (count == 0) { category.created_by = 123; category.updated_by = 123; CommonData.ReturnCode returnCode = categoryBL.InsertData(category); if (returnCode == CommonData.ReturnCode.Success) { TempData["Success"] = "Inserted Successfully!"; } else { TempData["Error"] = "Insert fail"; } Session["model.Category"] = null; return(RedirectToAction("Category")); } else { ModelState.AddModelError("code", "The Code already is existed!"); return(RedirectToAction("Add")); } } else { ModelState.AddModelError("code", "The code must not have spaces "); } } else { } } catch (DataException dex) { ModelState.AddModelError("", "Lỗi không xác định"); } SelectList listCategory = new SelectList(categoryBL.SelectDropdownData(), "id", "name"); ViewBag.ListCategory = listCategory; return(View("Add", category)); }
public ActionResult CategoryAdd(CategoryDTO category) { CategoryBL catelogy = new CategoryBL(); List <CategoryDTO> catelogydt; catelogy.SearchList(out catelogydt); ViewBag.CaterogyList = catelogydt; if (ModelState.IsValid) { CategoryBL bl = new CategoryBL(); int code = bl.CheckCode(category); if (code > 0) { TempData["Error"] = "Code already exists"; } else { TempData["Error"] = ""; category.created_by = 0; category.updated_by = 0; int result = bl.InsertData(category); if (result == 1) { TempData["Error"] = "Insert badly"; TempData["Success"] = ""; return(View(category)); } else { TempData["Error"] = ""; TempData["Success"] = "Insert successfully"; return(RedirectToAction("CategoryAdd")); } } } return(View(category)); }
public ActionResult AddCategory(CategoryDTO category) { try { if (ModelState.IsValid) { category.created_by = 113; CategoryBL categorybl = new CategoryBL(); if (category.code.Contains(" ")) { TempData["Error"] = "Don't input Space in Category Code"; return(View("Add", LoadCategoryAddForm(category))); } int count = categorybl.CountData(new CategoryDTO() { code = category.code }); if (count == 0) { categorybl.InsertData(category); } else { TempData["Error"] = "The Code already is exister!"; return(View("Add", LoadCategoryAddForm(category))); } return(RedirectToAction("Category")); } } catch (DataException dex) { ModelState.AddModelError("", "Unable to perform action. Please contact us."); return(RedirectToAction("SubmissionFailed", category)); } return(View("Add", LoadCategoryAddForm(category))); }