// GET: api/DeleteDocument public IHttpActionResult Get() { DocumentRepository documentData = new DocumentRepository(); ArchiveDocument archiveDocument = new ArchiveDocument(); FolderRepository folderRepository = new FolderRepository(); CurrentDocuments documentsToDelete = documentData.GetCurrentDocumentPathPdf(Utility.GetUserName()); string[] faxesToDelete = documentsToDelete.CurrentDocumentList.Split('~'); for (int i = 0; i < faxesToDelete.Length - 1; i++) { string[] documentName = faxesToDelete[i].Split('\\'); Logging.LogErrors(ConfigurationValues.ErrorLogPath, "Begin Archive"); archiveDocument.ArchiveTheDocument(documentName[documentName.Length - 1],faxesToDelete[i], Utility.GetUserName()); Logging.LogErrors(ConfigurationValues.ErrorLogPath, "End Archive"); try { System.IO.File.Delete(faxesToDelete[i]); folderRepository.DeleteFileInFolder(faxesToDelete[i]); } catch (Exception er) { Logging.LogErrors(ConfigurationValues.ErrorLogPath, er.ToString()); return BadRequest(er.ToString()); } try { documentData.DeleteDocumentInFolder(faxesToDelete[i]); } catch (Exception er) { Logging.LogErrors(ConfigurationValues.ErrorLogPath, er.ToString()); return BadRequest(er.ToString()); } } return Ok(); }
// POST: api/SendFax public IHttpActionResult Post([FromBody] Fax faxValues) { System.IO.Directory.CreateDirectory(ConfigurationValues.TemporaryFaxPath + Utility.GetUserName()); Logging.LogErrors(ConfigurationValues.ErrorLogPath, "Start Creating Fax"); OperationResult createFaxRecordOperationResult = new Models.OperationResult(); OperationResult sendFaxToMultiTechOperationResult = new Models.OperationResult(); FaxRepository faxData = new FaxRepository(); DocumentRepository documentData = new DocumentRepository(); string[] faxesToSendList = faxValues.FaxTo.Split('~'); SendFax sendFax = new SendFax(); try { for (int i = 0; i < faxesToSendList.Length - 1; i++) { Logging.LogErrors(ConfigurationValues.ErrorLogPath, "Getting fax information"); FaxingInformation faxingInformatonInitial = new FaxingInformation(); faxingInformatonInitial.DocumentList = faxValues.DocumentList; faxingInformatonInitial.FaxTo = faxesToSendList[i]; faxingInformatonInitial.Notes = faxValues.Notes; faxingInformatonInitial.From = faxValues.From; faxingInformatonInitial.Cover = faxValues.Cover; faxingInformatonInitial.CoverSheetOnly = faxValues.CoverOnly; Logging.LogErrors(ConfigurationValues.ErrorLogPath, "Getting fax information"); //Create Fax FaxingInformation faxingInformatonComplete = sendFax.CreateFax(faxingInformatonInitial); System.IO.File.Copy(ConfigurationValues.TemporaryFaxPath + Utility.GetUserName() + "\\" + faxingInformatonComplete.FaxName, ConfigurationValues.PernamentFaxPath + faxingInformatonComplete.FaxName, true); createFaxRecordOperationResult = faxData.SendFax(faxingInformatonComplete, ConfigurationValues.PernamentFaxPath + faxingInformatonComplete.FaxName, faxValues.From, faxValues.Notes); if (createFaxRecordOperationResult.Success) { sendFaxToMultiTechOperationResult = sendFaxMultitech.SendTheFax(faxingInformatonComplete.Name, faxingInformatonComplete.FaxPath, faxValues.From, faxingInformatonComplete.FaxNumber, createFaxRecordOperationResult.MessageList[0], ConfigurationValues.ApplicationPath); if (sendFaxToMultiTechOperationResult.Success) { if (faxValues.SendToEmr == "F") { ArchiveDocument = new ArchiveDocument(); CurrentDocuments faxTodocument = documentData.GetCurrentDocumentPathPdf(Utility.GetUserName()); string[] filesToDelete = faxTodocument.CurrentDocumentList.Split('~'); for (int j = 0; j < filesToDelete.Length - 1; j++) { try { string[] fileParts = filesToDelete[j].Split('\\'); ArchiveDocument.ArchiveTheDocument(fileParts[fileParts.Length - 1], filesToDelete[j], Utility.GetUserName()); File.Delete(filesToDelete[j]); } catch { } documentData.DeleteDocumentInFolder(filesToDelete[j]); } Logging.LogErrors(ConfigurationValues.ErrorLogPath, "Begin Delete file"); File.Delete(faxingInformatonComplete.FaxPath); File.Delete(ConfigurationValues.TemporaryFaxPath + Utility.GetUserName() + "\\cover.pdf"); Logging.LogErrors(ConfigurationValues.ErrorLogPath, "end delete file"); } } else { faxData.UpdateFaxRecord(sendFaxToMultiTechOperationResult.MessageList[0]); return BadRequest(sendFaxToMultiTechOperationResult.MessageList[0]); } } else { return BadRequest(createFaxRecordOperationResult.MessageList[0]); } } } catch (Exception er) { return BadRequest(er.ToString()); } CurrentDocuments documentsToDelete = documentData.GetCurrentDocumentPathPdf(Utility.GetUserName()); try { File.Delete(documentData.GetFullPathToDocument(Utility.GetUserName())); } catch { } string[] faxesToDelete = documentsToDelete.CurrentDocumentList.Split('~'); try { for (int i = 0; i < faxesToDelete.Length - 1; i++) { System.IO.File.Delete(ConfigurationValues.OutboundFaxDirectory + "\\" + Utility.GetUserName() + "\\" + faxesToDelete[i]); } } catch { } return Ok(); }