public ActionResult GetIncidents2(int queryId) { if (queryId < 1) { return(Json(new List <IncidentReportObject>(), JsonRequestBehavior.AllowGet)); } var query = new IncidentQueryBuilderServices().GetIncidentQuery(queryId); if (query == null || query.IncidentQueryId < 1) { return(Json(new List <IncidentReportObject>(), JsonRequestBehavior.AllowGet)); } var incidentList = new IncidentHistoryServices().GetOrderedIncidentReportObjects(query) ?? new List <IncidentReportObject>(); if (!incidentList.Any()) { return(Json(new List <IncidentReportObject>(), JsonRequestBehavior.AllowGet)); } var jsonResult = Json(incidentList, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return(jsonResult); }
private List <IncidentHistory> GetIncidentHistories(int itemsPerPage, int pageNumber, out int dataCount) { try { var incidentHistoryList = new IncidentHistoryServices().GetAllOrderedIncidentHistories(itemsPerPage, pageNumber, out dataCount); ViewBag.PrDataCount = dataCount.ToString(CultureInfo.InvariantCulture); var totalPages = dataCount / itemsPerPage; // Counting the last page if (dataCount % itemsPerPage != 0) { totalPages++; } ViewBag.PrTotalPages = totalPages; ViewBag.PrPage = pageNumber; if (!incidentHistoryList.Any()) { return(new List <IncidentHistory>()); } return(incidentHistoryList); } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); dataCount = 0; return(new List <IncidentHistory>()); } }
public ActionResult EditIncidentHistory(int id) { var incidentHistory = new IncidentHistory(); try { if (id < 1) { incidentHistory.Error = "Invalid Selection!"; incidentHistory.ErrorCode = -1; return(Json(incidentHistory, JsonRequestBehavior.AllowGet)); } var myViewObj = new IncidentHistoryServices().GetIncidentHistory(id); if (myViewObj == null || myViewObj.IncidentHistoryId < 1) { incidentHistory.Error = "Incident Information could not be retrieved."; incidentHistory.ErrorCode = -1; return(Json(incidentHistory, JsonRequestBehavior.AllowGet)); } Session["_incidentHistory"] = myViewObj; myViewObj.ErrorCode = myViewObj.IncidentHistoryId; return(Json(myViewObj, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); incidentHistory.Error = "An unknown error was encountered. Incident Information could not be retrieved."; incidentHistory.ErrorCode = -1; return(Json(incidentHistory, JsonRequestBehavior.AllowGet)); } }
public ActionResult GetIncidents(IncidentQuery queryBuilder) { if (queryBuilder == null) { return(Json(new List <IncidentReportObject>(), JsonRequestBehavior.AllowGet)); } if (queryBuilder.CompanyId < 1 && queryBuilder.CompanyId < 1 && queryBuilder.IncidentTypeId < 1 && ((queryBuilder.StartDate != null && queryBuilder.StartDate.Value.Year == 0001) || (queryBuilder.StartDate == null)) && ((queryBuilder.EndDate != null && queryBuilder.EndDate.Value.Year == 0001) || (queryBuilder.EndDate == null))) { return(Json(new List <IncidentReportObject>(), JsonRequestBehavior.AllowGet)); } var incidentList = new IncidentHistoryServices().GetOrderedIncidentReportObjects(queryBuilder) ?? new List <IncidentReportObject>(); if (!incidentList.Any()) { return(Json(new List <IncidentReportObject>(), JsonRequestBehavior.AllowGet)); } Session["_successfulIncidentQuery"] = queryBuilder; var jsonResult = Json(incidentList, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return(jsonResult); }
private List <IncidentHistory> GetIncidentHistories() { try { var incidentHistoryList = new IncidentHistoryServices().GetAllOrderedIncidentHistories(); if (!incidentHistoryList.Any()) { return(new List <IncidentHistory>()); } return(incidentHistoryList); } catch (Exception ex) { return(new List <IncidentHistory>()); } }
public ActionResult AddIncidentHistory(IncidentHistory incidentHistory) { ModelState.Clear(); ViewBag.LoadStatus = "0"; try { if (!ModelState.IsValid) { incidentHistory.Error = "Please supply all required fields and try again"; incidentHistory.ErrorCode = -1; return(Json(incidentHistory, JsonRequestBehavior.AllowGet)); } var wx = ValidateControl(incidentHistory); if (wx.Code < 1) { incidentHistory.Error = wx.Error; incidentHistory.ErrorCode = -1; return(Json(incidentHistory, JsonRequestBehavior.AllowGet)); } var k = new IncidentHistoryServices().AddIncidentHistory(incidentHistory); if (k < 1) { incidentHistory.Error = "Process Failed! Please contact the Admin or try again later"; incidentHistory.ErrorCode = 0; return(Json(incidentHistory, JsonRequestBehavior.AllowGet)); } incidentHistory.Error = "Record was added successfully"; incidentHistory.ErrorCode = 1; incidentHistory.IncidentHistoryId = k; return(Json(incidentHistory, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); incidentHistory.Error = "An unknown error was encountered. Request could not be serviced. Please try again later."; incidentHistory.ErrorCode = 0; return(Json(incidentHistory, JsonRequestBehavior.AllowGet)); } }
public ActionResult GetIncdentsByType(int incidentTypeId) { try { if (incidentTypeId < 1) { return(Json(new List <IncidentHistory>(), JsonRequestBehavior.AllowGet)); } var incidentHistoryList = new IncidentHistoryServices().GetIncidentHistoriesByType(incidentTypeId); if (!incidentHistoryList.Any()) { return(Json(new List <IncidentHistory>(), JsonRequestBehavior.AllowGet)); } return(Json(incidentHistoryList, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new List <IncidentHistory>(), JsonRequestBehavior.AllowGet)); } }
private List <DocObject> GetYears() { var jxs = new IncidentHistoryServices().GetIncidentYears(); if (!jxs.Any()) { return(new List <DocObject>()); } var tdv = new List <DocObject>(); jxs.ForEach(m => { var ts = int.Parse(m); if (!tdv.Exists(t => t.DocId == ts)) { tdv.Add(new DocObject { DocName = m, DocId = ts }); } }); return(tdv.OrderByDescending(m => m.DocName).ToList()); }
public ActionResult IncidentUpload(HttpPostedFileBase file) { try { if (file.ContentLength > 0) { const string folderPath = "~/BulkUploadTemplate"; var fileName = file.FileName; var path = folderPath + "/" + fileName; if (System.IO.File.Exists(Server.MapPath(path))) { System.IO.File.Delete(Server.MapPath(path)); } file.SaveAs(Server.MapPath(folderPath + "/" + fileName)); var mList = new List <IncidentHistory>(); var msg = string.Empty; if (!new IncidentUploadManager().Import(Server.MapPath(path), "incidents", ref mList, ref msg)) { return(View()); } if (!mList.Any()) { ViewBag.ErrorMessage = msg; ViewBag.ErrorCode = -1; //call Index Action here return(View()); } var errorList = new List <IncidentHistory>(); var successList = new List <IncidentHistory>(); foreach (var incidentHistoryInfo in mList) { var processedItem = new IncidentHistoryServices().AddIncidentHistory(incidentHistoryInfo); if (processedItem < 1) { errorList.Add(incidentHistoryInfo); } else { successList.Add(incidentHistoryInfo); } } if (!successList.Any()) { var error = msg.Length > 0 ? msg : "Bulk upload Failed! unknown error occurred"; ViewBag.ErrorCode = -2; ViewBag.ErrorMessage = error; return(View()); } if (errorList.Any() && successList.Any()) { var ts = successList.Count + " records were successfully uploaded." + "<br/>" + errorList.Count + " records could not be uploaded due to duplicates/unknown errors encountered."; ViewBag.ErrorCode = -1; if (msg.Length > 0) { ts += "<br/>" + msg; } ViewBag.ErrorMessage = ts; return(View()); } if (errorList.Any() && !successList.Any()) { var ts = errorList.Count + " records could not be uploaded due to duplicates/unknown errors encountered."; ViewBag.ErrorCode = -1; if (msg.Length > 0) { ts += "<br/>" + msg; } ViewBag.ErrorMessage = ts; return(View()); } if (!errorList.Any() && successList.Any() && msg.Length > 0) { ViewBag.ErrorCode = -1; //ViewBag.ErrorMessage = mList.Count + " records were successfully uploaded."; var tsx = successList.Count + " records were successfully uploaded."; tsx += "<br/>" + msg; ViewBag.ErrorMessage = tsx; return(View()); } if (!errorList.Any() && successList.Any() && (string.IsNullOrEmpty(msg) || msg.Length < 1)) { ViewBag.ErrorCode = 5; var tsx = successList.Count + " records were successfully uploaded."; ViewBag.ErrorMessage = tsx; return(View()); } } ViewBag.ErrorCode = -1; ViewBag.ErrorMessage = "The selected file is invalid"; return(View()); } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); ViewBag.ErrorCode = -1; ViewBag.ErrorMessage = "An unknown error was encountered. Data upload faild not be completed."; return(View()); } }
public ActionResult EditIncidentHistory(IncidentHistory incidentHistory) { ModelState.Clear(); ViewBag.LoadStatus = "0"; try { if (Session["_incidentHistory"] == null) { incidentHistory.Error = "Session has expired"; incidentHistory.ErrorCode = 0; return(Json(incidentHistory, JsonRequestBehavior.AllowGet)); } var oldIncidentHistory = Session["_incidentHistory"] as IncidentHistory; if (oldIncidentHistory == null || oldIncidentHistory.IncidentHistoryId < 1) { incidentHistory.Error = "Session has expired"; incidentHistory.ErrorCode = 0; return(Json(incidentHistory, JsonRequestBehavior.AllowGet)); } if (!ModelState.IsValid) { incidentHistory.Error = "Please supply all required fields and try again"; incidentHistory.ErrorCode = -1; return(Json(incidentHistory, JsonRequestBehavior.AllowGet)); } var wx = ValidateControl(incidentHistory); if (wx.Code < 1) { incidentHistory.Error = wx.Error; incidentHistory.ErrorCode = -1; return(Json(incidentHistory, JsonRequestBehavior.AllowGet)); } incidentHistory.Date = incidentHistory.IncidentDate.ToString("dd/MM/yyyy"); oldIncidentHistory.IncidentTypeId = incidentHistory.IncidentTypeId; oldIncidentHistory.Title = incidentHistory.Title; oldIncidentHistory.CompanyId = incidentHistory.CompanyId; oldIncidentHistory.Location = incidentHistory.Location; incidentHistory.Description = incidentHistory.Description; oldIncidentHistory.IncidentDate = incidentHistory.IncidentDate; oldIncidentHistory.ReportedBy = incidentHistory.ReportedBy; var k = new IncidentHistoryServices().UpdateIncidentHistory(oldIncidentHistory); if (k < 1) { incidentHistory.Error = "Process Failed! Please contact the Admin or try again later"; incidentHistory.ErrorCode = 0; return(Json(incidentHistory, JsonRequestBehavior.AllowGet)); } incidentHistory.Error = "Incident Information was successfully updated"; incidentHistory.ErrorCode = 1; return(Json(incidentHistory, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); incidentHistory.Error = "An unknown error was encountered. Request could not be serviced. Please try again later."; incidentHistory.ErrorCode = 0; return(Json(incidentHistory, JsonRequestBehavior.AllowGet)); } }