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)); } }
private static GenericValidator ValidateControl2(IncidentHistory model) { var gVal = new GenericValidator(); try { if (model.CompanyId < 1) { gVal.Error = "Please select a valid company"; gVal.Code = 0; return(gVal); } if (model.IncidentTypeId < 1) { gVal.Error = "Please select a valid Incident Type"; gVal.Code = 0; return(gVal); } gVal.Code = 1; return(gVal); } catch (Exception ex) { gVal.Error = "Process validation failed. Please supply all required entries and try again."; gVal.Code = 0; return(gVal); } }
public ActionResult DeleteIncident(int id) { var incidentHistory = new IncidentHistory(); try { if (id < 1) { incidentHistory.Error = "Invalid Selection"; incidentHistory.ErrorCode = 0; return(Json(incidentHistory, JsonRequestBehavior.AllowGet)); } if (new IncidentHistoryServices().DeleteIncidentHistoryCheckReferences(id)) { incidentHistory.Error = "Incident Information was successfully deleted."; incidentHistory.ErrorCode = 1; return(Json(incidentHistory, JsonRequestBehavior.AllowGet)); } incidentHistory.Error = "Process Failed! Please try again later"; incidentHistory.ErrorCode = 0; return(Json(incidentHistory, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); incidentHistory.Error = "An unknown error was encountered. Please contact the Administrator or try again later."; incidentHistory.ErrorCode = 0; return(Json(incidentHistory, JsonRequestBehavior.AllowGet)); } }
private static GenericValidator ValidateControl(IncidentHistory model) { var gVal = new GenericValidator(); try { if (string.IsNullOrEmpty(model.Title.Trim())) { gVal.Error = "Please provide Incident Title."; gVal.Code = 0; return(gVal); } if (string.IsNullOrEmpty(model.Location)) { gVal.Error = "Please provide Incident Location"; gVal.Code = 0; return(gVal); } if (string.IsNullOrEmpty(model.Description)) { gVal.Error = "Please provide Incident Description"; gVal.Code = 0; return(gVal); } if (model.IncidentDate.Year == 0001) { gVal.Error = "Please provide a valid Incident Date"; gVal.Code = 0; return(gVal); } if (model.CompanyId < 1) { gVal.Error = "Please select a valid Company"; gVal.Code = 0; return(gVal); } if (model.IncidentTypeId < 1) { gVal.Error = "Please select a valid Incident Type"; gVal.Code = 0; return(gVal); } gVal.Code = 1; return(gVal); } catch (Exception ex) { gVal.Error = "Process validation failed. Please supply all required entries and try again."; gVal.Code = 0; return(gVal); } }
private void UpdateHistory(Incident incident, IncidentHistoryElement element) { var incidentHistory = new IncidentHistory(); if (_incidentHistories.ContainsKey(incident.Scenario.Id)) { _incidentHistories.TryGetValue(incident.Scenario.Id, out incidentHistory); } if (incidentHistory != null) { incidentHistory.IncidentHistoryElements.Add(element); _incidentHistories[incident.Scenario.Id] = 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 int UpdateIncidentHistory(IncidentHistory incidentHistory) { try { if (incidentHistory == null) { return(-2); } using (var db = new DPRDataMigrationEngineDBEntities()) { db.IncidentHistories.Attach(incidentHistory); db.Entry(incidentHistory).State = EntityState.Modified; return(db.SaveChanges()); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public int AddIncidentHistory(IncidentHistory incidentHistory) { try { if (incidentHistory == null) { return(-2); } using (var db = new DPRDataMigrationEngineDBEntities()) { var processedItem = db.IncidentHistories.Add(incidentHistory); db.SaveChanges(); return(processedItem.IncidentHistoryId); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public int Update_IncidentHistory_mst_By_id(IncidentHistory objIncidentHistory) { return (int)ExecuteNonQuery(Sp_IncidentHistory_Update, new object[] { objIncidentHistory.Operationtime, objIncidentHistory.Operationownerid, objIncidentHistory.Operation, objIncidentHistory.Incidentid, objIncidentHistory.Historyid, objIncidentHistory.Description }); }
public int Insert_IncidentHistory_mst(IncidentHistory objIncidentHistory) { return (int)ExecuteNonQuery(Sp_IncidentHistory_Insert, new object[] { objIncidentHistory.Operationtime, objIncidentHistory.Operationownerid, objIncidentHistory.Operation, objIncidentHistory.Incidentid, objIncidentHistory.Description }); }
public object GenerateIncidentHistory_mstObject(ref IDataReader returnData) { IncidentHistory obj = new IncidentHistory(); while (returnData.Read()) { DateTime Mydatetime = new DateTime(); Mydatetime = (DateTime)returnData["Operationtime"]; obj.Operationtime = Mydatetime.ToString(); obj.Incidentid = (int)returnData["Incidentid"]; obj.Historyid = (int)returnData["Historyid"]; obj.Operationownerid = (int)returnData["Operationownerid"]; obj.Operation = (string)returnData["Operation"]; obj.Description = (string)returnData["Description"]; } returnData.Close(); returnData.Dispose(); return obj; }
public CollectionBase GenerateIncidentHistory_mstCollection(ref IDataReader returnData) { BLLCollection<IncidentHistory> col = new BLLCollection<IncidentHistory>(); while (returnData.Read()) { IncidentHistory obj = new IncidentHistory(); DateTime Mydatetime = new DateTime(); Mydatetime = (DateTime)returnData["Operationtime"]; obj.Operationtime = Mydatetime.ToString(); obj.Incidentid = (int)returnData["Incidentid"]; obj.Historyid = (int)returnData["Historyid"]; obj.Operationownerid = (int)returnData["Operationownerid"]; obj.Operation = (string)returnData["Operation"]; if (returnData["Description"] != DBNull.Value) { obj.Description = (string)returnData["Description"]; } col.Add(obj); } returnData.Close(); returnData.Dispose(); return col; }
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)); } }
private IncidentHistory ProcessRecord(DataRowView dv, ref string msg) { if (dv == null) { return(null); } try { var mInfo = new IncidentHistory { Title = dv.Row["IncidentTitle"].ToString().Trim() }; //[CompanyName],[IncidentType],[IncidentTitle] GetIncidentTypeId var incidentName = dv.Row["IncidentType"].ToString().Trim(); if (string.IsNullOrEmpty(incidentName)) { msg = "Incident Name is empty"; return(null); } var incidentId = new IncidentTypeServices().GetIncidentTypeId(incidentName.Trim()); if (incidentId < 1) { msg = "Incident Information could not be processed."; return(null); } mInfo.IncidentTypeId = incidentId; var companyName = dv.Row["CompanyName"].ToString().Trim(); if (string.IsNullOrEmpty(companyName)) { msg = "Company Name is empty"; return(null); } var companyId = new CompanyServices().GetCompanyId(companyName.Trim()); if (companyId < 1) { msg = "Company Information could not be processed."; return(null); } mInfo.CompanyId = companyId; var incidentDate = dv.Row["Date(yyyy/MM/dd)"].ToString().Trim(); if (!ValidateDateCompleted(incidentDate)) { msg = "Invalid input : Incident Date"; return(null); } DateTime d1; var realDate = DateTime.TryParse(incidentDate, out d1); if (!realDate || d1.Year == 0001) { msg = "Invalid input : Incident Date"; return(null); } mInfo.IncidentDate = d1; var location = dv.Row["Location"].ToString().Trim(); if (string.IsNullOrEmpty(location.Trim())) { msg = "Incident Location is empty."; return(null); } mInfo.Location = location; var description = dv.Row["Description"].ToString().Trim(); if (string.IsNullOrEmpty(description.Trim())) { msg = "Incident Description is empty."; return(null); } mInfo.Description = description; var incidentReporter = dv.Row["ReportedBy"].ToString().Trim(); if (!string.IsNullOrEmpty(incidentReporter.Trim())) { mInfo.ReportedBy = incidentReporter; } return(mInfo); } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(null); } }