public ActionResult Add(DSRCManagementSystem.Models.Category objmodel) { DSRCManagementSystemEntities1 objdb = new DSRCManagementSystemEntities1(); DSRCManagementSystem.Category obj = new DSRCManagementSystem.Category(); try { obj.CategoryName = objmodel.CategoryName.Trim(); obj.IsActive = true; objdb.AddToCategories(obj); if (!objdb.Categories.Any(cobj => cobj.IsActive == true && cobj.CategoryName.Trim() == obj.CategoryName.Trim())) { objdb.SaveChanges(); } else { return(Json(new { Result = "Already", URL = @Url.Action("AlertPopUp", "Popup") }, JsonRequestBehavior.AllowGet)); } } catch (Exception Ex) { string actionName = this.ControllerContext.RouteData.Values["action"].ToString(); string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); ExceptionHandlingController.ExceptionDetails(Ex, actionName, controllerName); } return(Json(new { Result = "Success", URL = @Url.Action("AlertPopUp", "Popup") }, JsonRequestBehavior.AllowGet)); }
public ActionResult EditCategory(DSRCManagementSystem.Models.Category objmodel) { DSRCManagementSystemEntities1 objdb = new DSRCManagementSystemEntities1(); var res = ""; try { objmodel.CategoryID = Convert.ToInt32(Session["CategoryId"]); var value = objdb.Categories.Where(x => x.CategoryID == objmodel.CategoryID).Select(o => o).FirstOrDefault(); if (!objdb.Categories.Any(cobj => cobj.IsActive == true && cobj.CategoryName.Trim() == objmodel.CategoryName.Trim())) { value.CategoryName = objmodel.CategoryName; objdb.SaveChanges(); res = "Success"; } else { // return Json(new { Result = "Already", URL = @Url.Action("AlertPopUp", "Popup") }, JsonRequestBehavior.AllowGet); res = "Already"; } } catch (Exception Ex) { string actionName = this.ControllerContext.RouteData.Values["action"].ToString(); string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); ExceptionHandlingController.ExceptionDetails(Ex, actionName, controllerName); } return(Json(new { Result = res, URL = @Url.Action("AlertPopUp", "Popup") }, JsonRequestBehavior.AllowGet)); }
public ActionResult EditCategory(int Id) { DSRCManagementSystemEntities1 objdb = new DSRCManagementSystemEntities1(); DSRCManagementSystem.Models.Category obj = new DSRCManagementSystem.Models.Category(); try { var value = objdb.Categories.Where(x => x.CategoryID == Id).Select(o => o).FirstOrDefault(); obj.CategoryName = value.CategoryName; Session["CategoryId"] = Id; } catch (Exception Ex) { string actionName = this.ControllerContext.RouteData.Values["action"].ToString(); string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); ExceptionHandlingController.ExceptionDetails(Ex, actionName, controllerName); } return(View(obj)); }