public async Task <IActionResult> OnGetAsync(string id) { if (id == null) { return(NotFound()); } Documents = await _context.Documents.FirstOrDefaultAsync(m => m.DocumentsID == id); if (Documents == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(string id) { if (id == null) { return(NotFound()); } Documents = await _context.Documents.FindAsync(id); if (System.IO.File.Exists(hostingEnvironment.WebRootPath + Documents.DocumentPath + "")) { System.IO.File.Delete(hostingEnvironment.WebRootPath + Documents.DocumentPath + ""); } if (Documents != null) { _context.Documents.Remove(Documents); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public ActionResult DownloadFile(int policyID, long DocID, string fileName) { try { Models.Documents Document = Models.DocumentMethods.GetDocumentByID(DocID); Models.UsageData.InsertNewUsage(9, (int)Session["CustomerID"], "Document ID " + DocID.ToString() + " - " + fileName); Response.Clear(); Response.ContentType = "application/octect-stream"; Response.AddHeader("Content-Disposition", "filename=" + fileName); long filesize = (long)Document.Document.Length; Response.AddHeader("Content-Lenght", filesize.ToString()); Response.BinaryWrite(Document.Document); Response.Flush(); Response.Close(); } catch { } return(RedirectToAction("Insurances", "PropertyDetails", new { PolicyID = policyID })); }
private async void addButton_Click(object sender, EventArgs e) { if (!VerifyDocumentsValues(out var name)) { return; } var document = new Models.Documents() { FileName = name }; var folder = localFileManager.CreateFileFolder("Document_" + document.Id.ToString()); var format = ".pdf"; var trueName = SearchNames(folder, name); folder = folder + @"\" + trueName + format; //folder = $@"{folder}\{name}" + ".pdf"; document.FileName = trueName; Document doc = new Document(); PdfWriter.GetInstance(doc, new FileStream(folder, FileMode.Create)); doc.Open(); string ttf = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIAL.TTF"); BaseFont baseFont = BaseFont.CreateFont(ttf, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); Font font = new Font(baseFont, iTextSharp.text.Font.DEFAULTSIZE, iTextSharp.text.Font.NORMAL); var dateFrom = dateTimePickerFrom.Value; var dateTo = dateTimePickerTo.Value; var currentOrders = await _ordersRepository.GetOrdersinDates(dateFrom, dateTo); for (int i = 0; i < currentOrders.Count; i++) { if (currentOrders[i].TimeCompleted != DateTime.MinValue) { var currentuser = await _clientsRepository.GetClient(currentOrders[i].ClientId); var currentworker = await _workerRepository.GetWorker(currentOrders[i].WorkerId); PdfPTable table = new PdfPTable(2); PdfPCell cell = new PdfPCell(new Phrase("Заказ " + $"{currentOrders[i].Id}", font)); cell.Colspan = 2; cell.HorizontalAlignment = 1; cell.Border = 0; table.AddCell(cell); table.AddCell(new Phrase("ID", font)); table.AddCell(new Phrase(currentOrders[i].Id.ToString(), font)); table.AddCell(new Phrase("ФИО заказчика", font)); table.AddCell(new Phrase(currentuser.FIO, font)); table.AddCell(new Phrase("телефон заказчика", font)); table.AddCell(new Phrase(currentuser.ContactNumber, font)); table.AddCell(new Phrase("ФИО исполнителя", font)); table.AddCell(new Phrase(currentworker.FIO, font)); var col = new PdfPCell(new Phrase(currentOrders[i].Payment.ToString(), font)); var col2 = new PdfPCell(new Phrase(currentOrders[i].PaymentIsDone.ToString(), font)); if (currentOrders[i].Payment > currentOrders[i].PaymentIsDone) { col.BackgroundColor = BaseColor.RED; col2.BackgroundColor = BaseColor.RED; } else { col.BackgroundColor = BaseColor.WHITE; col2.BackgroundColor = BaseColor.WHITE; } table.AddCell(new Phrase("Сумма к оплате", font)); table.AddCell(col); table.AddCell(new Phrase("Оплачено", font)); table.AddCell(col2); table.AddCell(new Phrase("Дата завершения", font)); table.AddCell(new Phrase(currentOrders[i].TimeCompleted.ToString(), font)); doc.Add(table); } } doc.Close(); document.FileLink = folder; document.TimeCreated = DateTime.Now; refreshGridWidth(); await _documentsRepository.CreateDocuments(document); await UpdateDataGridViewDocuments(dateTimePickerFrom.Value, dateTimePickerTo.Value); await UpdateDataGridViewOrders(dateTimePickerFrom.Value, dateTimePickerTo.Value); }