public ActionResult DeleteStructure(long id) { var gVal = new GenericValidator(); try { if (id < 1) { gVal.Code = -1; gVal.Error = "Invalid selection"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var delStatus = new StructureServices().DeleteStructure(id); if (delStatus < 1) { gVal.Code = -1; gVal.Error = "Structure could not be deleted. Please try again later."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = 5; gVal.Error = "Structure Information was successfully deleted"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception) { return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public ActionResult EditStructure(StructureObject structure) { var gVal = new GenericValidator(); try { if (!ModelState.IsValid) { gVal.Code = -1; gVal.Error = "Plese provide all required fields and try again."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var stat = ValidateStructure(structure); if (stat.Code < 1) { return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (Session["_structure"] == null) { gVal.Code = -1; gVal.Error = "Session has timed out."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var oldstructure = Session["_structure"] as StructureObject; if (oldstructure == null) { gVal.Code = -1; gVal.Error = "Session has timed out."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } oldstructure.Name = structure.Name.Trim(); oldstructure.Description = structure.Description; var docStatus = new StructureServices().UpdateStructure(oldstructure); if (docStatus < 1) { gVal.Code = -1; gVal.Error = docStatus == -3 ? "Structure already exists." : "Structure information could not be updated. Please try again later"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = oldstructure.StructureId; gVal.Error = "Structure information was successfully updated"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception) { gVal.Code = -1; gVal.Error = "Structure information could not be updated. Please try again later"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public ActionResult GetStructureObjects(JQueryDataTableParamModel param) { try { IEnumerable <StructureObject> filteredParentMenuObjects; int countG; var pagedParentMenuObjects = GetStructures(param.iDisplayLength, param.iDisplayStart, out countG); if (!string.IsNullOrEmpty(param.sSearch)) { filteredParentMenuObjects = new StructureServices().Search(param.sSearch); } else { filteredParentMenuObjects = pagedParentMenuObjects; } if (!filteredParentMenuObjects.Any()) { return(Json(new List <StructureObject>(), JsonRequestBehavior.AllowGet)); } //var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]); Func <StructureObject, string> orderingFunction = (c => c.Name); var sortDirection = Request["sSortDir_0"]; // asc or desc filteredParentMenuObjects = sortDirection == "desc" ? filteredParentMenuObjects.OrderBy(orderingFunction) : filteredParentMenuObjects.OrderByDescending(orderingFunction); var displayedPersonnels = filteredParentMenuObjects; var result = from c in displayedPersonnels select new[] { Convert.ToString(c.StructureId), c.Name }; return(Json(new { param.sEcho, iTotalRecords = countG, iTotalDisplayRecords = countG, aaData = result }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(Json(new List <StructureObject>(), JsonRequestBehavior.AllowGet)); } }
public ActionResult GetStructures() { try { var structures = new StructureServices().GetStructures(); if (!structures.Any()) { return(Json(new List <StructureObject>(), JsonRequestBehavior.AllowGet)); } return(Json(structures, JsonRequestBehavior.AllowGet)); } catch (Exception) { return(Json(new List <StructureObject>(), JsonRequestBehavior.AllowGet)); } }
public ActionResult AddStructure(StructureObject structure) { var gVal = new GenericValidator(); try { if (!ModelState.IsValid) { gVal.Code = -1; gVal.Error = "Plese provide all required fields and try again."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var importerInfo = GetLoggedOnUserInfo(); if (importerInfo.Id < 1) { gVal.Error = "Your session has timed out"; gVal.Code = -1; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var validationResult = ValidateStructure(structure); if (validationResult.Code == 1) { return(Json(validationResult, JsonRequestBehavior.AllowGet)); } var appStatus = new StructureServices().AddStructure(structure); if (appStatus < 1) { validationResult.Code = -1; validationResult.Error = appStatus == -2 ? "Structure upload failed. Please try again." : "The Structure Information already exists"; return(Json(validationResult, JsonRequestBehavior.AllowGet)); } gVal.Code = appStatus; gVal.Error = "Structure was successfully added."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception) { gVal.Error = "Structure processing failed. Please try again later"; gVal.Code = -1; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public ActionResult GetStructure(long id) { try { var structure = new StructureServices().GetStructure(id); if (structure == null || structure.StructureId < 1) { return(Json(new StructureObject(), JsonRequestBehavior.AllowGet)); } Session["_structure"] = structure; return(Json(structure, JsonRequestBehavior.AllowGet)); } catch (Exception) { return(Json(new StructureObject(), JsonRequestBehavior.AllowGet)); } }