public IActionResult OnPostUploadAttachments() { GetUserName(); var data = Request.Form; foreach (var file in data.Files) { MachineTrainFiles New_Machine_Train_File = new MachineTrainFiles(); Console.WriteLine(file.FileName); New_Machine_Train_File.FileName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(file.FileName); New_Machine_Train_File.FkMachineTrainId = Machine_Train_Id; New_Machine_Train_File.UploadDate = DateTime.Now; New_Machine_Train_File.UploadedBy = Current_User; _context.MachineTrainFiles.Add(New_Machine_Train_File); try { _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!MachineFileExists(New_Machine_Train_File.PkFilePathId)) { return(NotFound()); } else { throw; } } string save_path = $"wwwroot\\MachineAttach\\{New_Machine_Train_File.FileName}"; //string save_path = $"c:\\MachineAttach\\{New_Machine_Train_File.FileName}"; using (var fileStream = new FileStream(save_path, FileMode.Create)) { file.CopyTo(fileStream); } } return(new RedirectToPageResult("/Machinenotes", new { id = Machine_Train_Id })); }
public async Task <IActionResult> OnPostUpdateReportFault() { GetUserName(); Current_Displayed_Report = _context.VReportSummary.FirstOrDefault(r => r.ReportId == Report_To_Update.PkReportId); //--------------- Update Fault if FaultType is null ----------------------------// if (Current_Displayed_Report.FaultTypeId == null) { foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(Fault_To_Update)) { string name = descriptor.Name; object value = descriptor.GetValue(Fault_To_Update); Console.WriteLine($"{name} = {value}"); } var Updated_Fault = await _context.Fault.FirstOrDefaultAsync(f => f.PkFaultId == Fault_To_Update.PkFaultId); Updated_Fault.FkTechnologyId = Fault_To_Update.FkTechnologyId; Updated_Fault.FkPrimaryComponentTypeId = Fault_To_Update.FkPrimaryComponentTypeId; Updated_Fault.FkPrimaryComponentSubtypeId = Fault_To_Update.FkPrimaryComponentSubtypeId; Updated_Fault.FkFaultTypeId = Fault_To_Update.FkFaultTypeId; Updated_Fault.FkFaultSubtypeId = Fault_To_Update.FkFaultSubtypeId; Updated_Fault.FaultLocation = Fault_To_Update.FaultLocation; _context.Attach(Updated_Fault).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FaultExists(Fault_To_Update.PkFaultId)) { return(NotFound()); } else { throw; } } } //--------------- Update Fault if FaultType is null ----------------------------// //--------------- Update Report----------------------------// //foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(Report_To_Update)) //{ // string name = descriptor.Name; // object value = descriptor.GetValue(Report_To_Update); // Console.WriteLine($"{name} = {value}"); //} var Updated_Report = await _context.Report.FirstOrDefaultAsync(f => f.PkReportId == Report_To_Update.PkReportId); Updated_Report.FkReportTypeId = Report_To_Update.FkReportTypeId; Updated_Report.FkConditionId = Report_To_Update.FkConditionId; Updated_Report.ReportDate = Report_To_Update.ReportDate; Updated_Report.Observations = Report_To_Update.Observations; Updated_Report.Actions = Report_To_Update.Actions; Updated_Report.ExternalNotes = Report_To_Update.ExternalNotes; Updated_Report.NotificationNo = Report_To_Update.NotificationNo; Updated_Report.WorkOrderNo = Report_To_Update.WorkOrderNo; Updated_Report.AnalystNotes = Report_To_Update.AnalystNotes; Updated_Report.FkReportStageId = Report_To_Update.FkReportStageId; _context.Attach(Updated_Report).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReportExists(Report_To_Update.PkReportId)) { return(NotFound()); } else { throw; } } //--------------- Update Report----------------------------// //--------------- Upload Attachments----------------------------// var UploadFileList = HttpContext.Request.Form.Files; foreach (var file in UploadFileList) { ReportFiles New_ReportFile = new ReportFiles(); Console.WriteLine(file.FileName); New_ReportFile.FileName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(file.FileName); New_ReportFile.FkReportId = Report_To_Update.PkReportId; New_ReportFile.UploadDate = DateTime.Now; New_ReportFile.UploadedBy = Current_User; _context.ReportFiles.Add(New_ReportFile); try { _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ReportFileExists(New_ReportFile.PkFilePathId)) { return(NotFound()); } else { throw; } } string save_path = $"wwwroot\\MachineAttach\\{New_ReportFile.FileName}"; //string save_path = $"c:\\MachineAttach\\{New_Machine_Train_File.FileName}"; using (var fileStream = new FileStream(save_path, FileMode.Create)) { file.CopyTo(fileStream); } } //--------------- Upload Attachments----------------------------// return(RedirectToPage("/ReviewReports", new { id = Report_To_Update.PkReportId })); }