public JsonResult ToggleActive(int id = 0) { try { RDCategory model = db.RDCategories.Find(id); if (model != null) { if (model.active) { BoolString validation = model.BeforeInactive(db); if (validation.BoolValue) { return(Json(new { Message = validation.StringValue }, JsonRequestBehavior.AllowGet)); } model.active = !model.active; db.SaveChanges(); validation = model.AfterInactive(db); if (validation.BoolValue) { return(Json(new { Message = validation.StringValue }, JsonRequestBehavior.AllowGet)); } return(Json(new { id = model.id, MessageSucess = "That Category Inactive successfully." }, JsonRequestBehavior.AllowGet)); } else { BoolString validation = model.BeforeActive(db); if (validation.BoolValue) { return(Json(new { Message = validation.StringValue }, JsonRequestBehavior.AllowGet)); } model.active = !model.active; db.SaveChanges(); validation = model.AfterActive(db); if (validation.BoolValue) { return(Json(new { Message = validation.StringValue }, JsonRequestBehavior.AllowGet)); } return(Json(new { id = model.id, MessageSucess = "That Category Active successfully." }, JsonRequestBehavior.AllowGet)); } } return(Json(new { Message = "This record no longer exists" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { Message = Helper.ModeralException(ex).Replace("@table", "Category") }, JsonRequestBehavior.AllowGet)); } }