public ActionResult SubCategory(int page = 1) { var model = new SubCategorySetupViewModel(); model.SubCategorySetupViewModelList = _proCommon.GetAllSubCategories(); ViewBag.currentPage = page; return(View(model)); }
public ActionResult InsertUpdateSubCategory(SubCategorySetupViewModel model) { if (!ModelState.IsValid) { return(View(model)); } if (_proCommon.InsertUpdateSubCategory(model)) { return(RedirectToAction("SubCategory")); } return(View(model)); }
public bool InsertUpdateSubCategory(SubCategorySetupViewModel model) { try { using (var con = new DirectoryEntities()) { if (model.DirectorySubCategoryId > 0) { var record = con.tblDirectorySubCategories.Where(x => x.DirectorySubCategoryId == model.DirectorySubCategoryId).FirstOrDefault(); if (record != null) { record.DirectorySubCategoryId = model.DirectorySubCategoryId; record.DirectorySubCategoryName = model.DirectorySubCategoryName; record.DirectoryCategoryId = model.DirectoryCategoryId; con.Entry(record).State = System.Data.Entity.EntityState.Modified; } } else { tblDirectorySubCategory subCategory = new tblDirectorySubCategory() { DirectorySubCategoryId = model.DirectorySubCategoryId, DirectorySubCategoryName = model.DirectorySubCategoryName, DirectoryCategoryId = model.DirectoryCategoryId }; //subCategory.CreatedBy = Utility.GetCurrentLoginUser(); subCategory.CreatedDate = DateTime.Now.ToShortDateString().ToString(); con.tblDirectorySubCategories.Add(subCategory); } con.SaveChanges(); return(true); } } catch (Exception) { return(false); } }