public JsonResult ToggleActive(int id = 0) { try { BaseColumn model = db.BaseColumns.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 Column 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 Column 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", "Column") }, JsonRequestBehavior.AllowGet)); } }