public ActionResult Category(string page, ResearchCategoryModel model) { ModelState.Clear(); CategoryBL bl = new CategoryBL(); if (model == null) { model = new ResearchCategoryModel(); model.Category = new CategoryDTO(); model.lstCategory = new List <CategoryDTO>(); } else { if (model.Category == null) { model.Category = new CategoryDTO(); } if (model.lstCategory == null) { model.lstCategory = new List <CategoryDTO>(); } } if (page == null) { page = "1"; } model.page_count = bl.CountData(model.Category); List <CategoryDTO> list; model.Category.page = int.Parse(page); bl.SearchData(model.Category, out list); model.lstCategory = list; TempData["Success"] = model.page_count + " row(s) has found."; return(View(model)); }
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 Category(CategoryModel model, int page = 1) { ModelState.Clear(); if (model == null) { model = new CategoryModel(); model.Category = new CategoryDTO(); model.Categorys = new StaticPagedList <CategoryDTO>(new List <CategoryDTO>(), 1, 20, 0); } else { if (model.Category == null) { if (Session["model.Category"] != null && page >= 1) { model.Category = Session["model.Category"] as CategoryDTO; } else { model.Category = new CategoryDTO(); } } else { Session["model.Category"] = model.Category; } } CategoryBL bl = new CategoryBL(); model.Category.page = page; model.Category.page_count = bl.CountData(model.Category); TempData["SearchCount"] = model.Category.page_count + " row(s) has found."; SelectList listCategory = new SelectList(categoryBL.SelectDropdownData(), "id", "name"); ViewBag.ListCategory = listCategory; List <CategoryDTO> list; bl.SearchData(model.Category, out list); model.Categorys = new StaticPagedList <CategoryDTO>(list, model.Category.page, 20, model.Category.page_count); return(View(model)); }
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))); }