public async Task <IActionResult> OnPostCreateNewMachinenote() { GetUserName(); New_Machine_Note.MachineTrainNoteIsActive = true; New_Machine_Note.NoteDate = DateTime.Now; New_Machine_Note.MachineTrainNoteIsActive = true; New_Machine_Note.AnalystName = Current_User; _context.MachineTrainNotes.Add(New_Machine_Note); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MachineNoteExists(New_Machine_Note.FkMachineTrainId)) { return(NotFound()); } else { throw; } } return(RedirectToPage("/Machinenotes", new { id = New_Machine_Note.FkMachineTrainId })); }
public async Task <IActionResult> OnPostEditRouteCall() { GetUserName(); //Console.WriteLine(" ------------------------------ Edit Route Call ------------------------------"); //Console.WriteLine(Edit_Route_Call.Schedule_Date); //Console.WriteLine(Edit_Route_Call.PK_CallId); var Updated_Route_Call = await _context.RouteCall.FirstOrDefaultAsync(m => m.PkCallId == Edit_Route_Call.PkCallId); Updated_Route_Call.ScheduleDate = Edit_Route_Call.ScheduleDate; Updated_Route_Call.ModifiedBy = Current_User; _context.Attach(Updated_Route_Call).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RouteCallExists(Edit_Route_Call.PkCallId)) { return(NotFound()); } else { throw; } } //Console.WriteLine(" ------------------------------ Finish Editing ------------------------------"); return(RedirectToPage("/ScheduleMaintenance")); }
public async Task <IActionResult> OnPostDeleteReportFile() { var ReportFile = await _context.ReportFiles.FindAsync(ReportFileID_ToDelete); if (ReportFile == null) { return(NotFound()); } try { _context.ReportFiles.Remove(ReportFile); await _context.SaveChangesAsync(); return(RedirectToPage("/ReviewReports", new { id = SelectedReportId })); } catch (DbUpdateException /* ex */) { throw; } }
public async Task <IActionResult> OnPostCreateReport() { GetUserName(); V_Report_Summary_All = await _context.VReportSummary .AsNoTracking() .ToListAsync(); // only process selected machines InputReportList = InputReportList.Where(r => MainOptionList.Contains(r.MainOption)).ToList(); GeneratedReportSummary.Clear(); foreach (var inputreport in InputReportList) { Console.WriteLine("{0}--{1}--{2}--{3}--{4}", inputreport.MachineTrainId, inputreport.MainOption, inputreport.Reason, inputreport.Comments, inputreport.PK_CallId); if (inputreport.MainOption == "missed") // Missed { if (inputreport.Reason == 0) { log_str = $"Failed to create report for machine {inputreport.Machine_Train} - {inputreport.Machine_Train_Long_Name} in call {inputreport.RouteDescription}. You must SELECT A REASON for the missed machine!"; GeneratedReportSummary.Add(log_str); Console.WriteLine(log_str); } else { var new_missed_sruvey = new MissedSurvey() { FkMachineTrainId = inputreport.MachineTrainId, Reason = reason_list[inputreport.Reason], Comments = inputreport.Comments, ReportedMissedDate = DateTime.Now, ReportedMissedBy = Current_User, OriginCallId = inputreport.PK_CallId }; _context.MissedSurvey.Add(new_missed_sruvey); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FaultExists(new_missed_sruvey.PkMissedSurveyId)) { return(NotFound()); } else { throw; } } log_str = $"Missed Survey created for machine {inputreport.Machine_Train} - {inputreport.Machine_Train_Long_Name} in route {inputreport.RouteDescription}"; GeneratedReportSummary.Add(log_str); Console.WriteLine(log_str); } } else if (inputreport.MainOption == "good") // No Action { // Is there an open fault? if (inputreport.Status == "Open") { // Was the latest condition a 2 (No Action) if (inputreport.Condition == "No Action") { /* * Create a new report on the same fault. * -- Set condition_mag = 2, routine and released */ var new_report = new Report() { FkFaultId = inputreport.FaultId, ReportDate = DateTime.Now, MeasurementDate = DateTime.Now, FkConditionId = 1, // No Action Mag = 2 FkReportTypeId = 1, // Routine FkReportStageId = 4, //released AnalystName = Current_User, ReportIsActive = true, OriginCallId = inputreport.PK_CallId }; _context.Report.Add(new_report); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReportExists(new_report.PkReportId)) { return(NotFound()); } else { throw; } } } else // Was the latest condition a 2 (No Action) { /* * Close the existing fault * -- Stamp the close date field in the fault table * -- Input the comment to the fault table */ var Edit_Fault = await _context.Fault.FirstOrDefaultAsync(n => n.PkFaultId == inputreport.FaultId); if (Edit_Fault == null) { return(NotFound()); } Edit_Fault.CloseDate = DateTime.Now; Edit_Fault.ClosureComment = inputreport.Comments; _context.Attach(Edit_Fault).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FaultExists(Edit_Fault.PkFaultId)) { return(NotFound()); } else { throw; } } /* * Create a new fault on this machine * -- set the fault type to no fault * -- Create a new report on the new fault. * -- Set condition_mag = 2, routine and released */ var new_fault = new Fault() { FkMachineTrainId = inputreport.MachineTrainId, FkPrimaryComponentTypeId = 1, FkTechnologyId = 1, FkFaultTypeId = 1, CreateDate = DateTime.Now, FaultIsActive = true }; _context.Fault.Add(new_fault); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FaultExists(new_fault.PkFaultId)) { return(NotFound()); } else { throw; } } var new_report = new Report() { FkFaultId = new_fault.PkFaultId, ReportDate = DateTime.Now, MeasurementDate = DateTime.Now, FkConditionId = 1, FkReportTypeId = 1, FkReportStageId = 4, AnalystName = Current_User, ReportIsActive = true, OriginCallId = inputreport.PK_CallId }; _context.Report.Add(new_report); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReportExists(new_report.PkReportId)) { return(NotFound()); } else { throw; } } } } else // Is there an open fault? { /* * Create a new fault on this machine * -- set the fault type to no fault * -- Create a new report on the new fault. * -- Set condition_mag = 2, routine and released */ var new_fault = new Fault() { FkMachineTrainId = inputreport.MachineTrainId, FkPrimaryComponentTypeId = 1, FkTechnologyId = 1, FkFaultTypeId = 1, CreateDate = DateTime.Now, FaultIsActive = true }; _context.Fault.Add(new_fault); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FaultExists(new_fault.PkFaultId)) { return(NotFound()); } else { throw; } } var new_report = new Report() { FkFaultId = new_fault.PkFaultId, ReportDate = DateTime.Now, MeasurementDate = DateTime.Now, FkConditionId = 1, FkReportTypeId = 1, FkReportStageId = 4, AnalystName = Current_User, ReportIsActive = true, OriginCallId = inputreport.PK_CallId }; _context.Report.Add(new_report); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReportExists(new_report.PkReportId)) { return(NotFound()); } else { throw; } } } } else if (inputreport.MainOption == "anomaly") // Anomaly { // Is there an open fault? if (inputreport.Status == "Open") { // Was the latest condition a 2 (No Action) if (inputreport.Condition == "No Action") { /* * Close the existing fault * -- Stamp the close date field in the fault table */ var Edit_Fault = await _context.Fault.FirstOrDefaultAsync(n => n.PkFaultId == inputreport.FaultId); if (Edit_Fault == null) { return(NotFound()); } Edit_Fault.CloseDate = DateTime.Now; _context.Attach(Edit_Fault).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FaultExists(Edit_Fault.PkFaultId)) { return(NotFound()); } else { throw; } } Console.WriteLine("Close the existing fault"); /* * Create a new fault on this machine * -- Create a new report on the new fault. * -- Set condition_mag = 3, routine and In progress */ var new_fault = new Fault() { FkMachineTrainId = inputreport.MachineTrainId, FkPrimaryComponentTypeId = 1, FkTechnologyId = 1, CreateDate = DateTime.Now, FaultIsActive = true }; _context.Fault.Add(new_fault); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FaultExists(new_fault.PkFaultId)) { return(NotFound()); } else { throw; } } var new_report = new Report() { FkFaultId = new_fault.PkFaultId, ReportDate = DateTime.Now, MeasurementDate = DateTime.Now, FkConditionId = 2, FkReportTypeId = 1, FkReportStageId = 1, AnalystName = Current_User, ReportIsActive = true, OriginCallId = inputreport.PK_CallId }; _context.Report.Add(new_report); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReportExists(new_report.PkReportId)) { return(NotFound()); } else { throw; } } Console.WriteLine("Set condition_mag = 3, routine and In progress"); } else { /* * Create a new report on the same fault. * -- Set condition_mag = 2, routine and released */ var new_report = new Report() { FkFaultId = inputreport.FaultId, ReportDate = DateTime.Now, MeasurementDate = DateTime.Now, FkConditionId = 1, FkReportTypeId = 1, FkReportStageId = 4, AnalystName = Current_User, ReportIsActive = true, OriginCallId = inputreport.PK_CallId }; _context.Report.Add(new_report); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReportExists(new_report.PkReportId)) { return(NotFound()); } else { throw; } } Console.WriteLine("Create a new report on the same fault. -- Set condition_mag = 2, routine and released"); } } else { /* * Create a new fault on this machine * -- Create a new report on the new fault. * -- Set condition_mag = 3, routine and In progress */ var new_fault = new Fault() { FkMachineTrainId = inputreport.MachineTrainId, FkPrimaryComponentTypeId = 1, FkTechnologyId = 1, CreateDate = DateTime.Now, FaultIsActive = true }; _context.Fault.Add(new_fault); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FaultExists(new_fault.PkFaultId)) { return(NotFound()); } else { throw; } } var new_report = new Report() { FkFaultId = new_fault.PkFaultId, ReportDate = DateTime.Now, MeasurementDate = DateTime.Now, FkConditionId = 2, FkReportTypeId = 1, FkReportStageId = 1, AnalystName = Current_User, ReportIsActive = true, OriginCallId = inputreport.PK_CallId }; _context.Report.Add(new_report); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReportExists(new_report.PkReportId)) { return(NotFound()); } else { throw; } } Console.WriteLine("Create a new fault on this machine -- Create a new report on the new fault. -- Set condition_mag = 3, routine and In progress"); } } else { log_str = $"Nothing changed for machine {inputreport.Machine_Train} - {inputreport.Machine_Train_Long_Name} in route {inputreport.RouteDescription}"; GeneratedReportSummary.Add(log_str); Console.WriteLine(log_str); } } Console.WriteLine(GeneratedReportSummary.Count); return(RedirectToPage("/CreateReports")); }