Non missura cutem, nisi plena cruoris hirudo
This commit is contained in:
parent
8921f8f81b
commit
ab82833487
@ -195,114 +195,103 @@ namespace WorkerWebApp.Controllers
|
||||
return View(data);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateReportWord(List<int> procedures, DateTime dateFrom, DateTime dateTo)
|
||||
{
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
if (dateFrom == DateTime.MinValue || dateTo == DateTime.MinValue)
|
||||
{
|
||||
throw new Exception("Введены не все данные!");
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> CreateReportWord(List<int> procedures, DateTime dateFrom, DateTime dateTo, [FromServices] IWebHostEnvironment hostingEnvironment)
|
||||
{
|
||||
// Проверки ввода и авторизации
|
||||
var folderName = "C:\\отчеты";
|
||||
var fileName = $"Список процедур {DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")}.docx";
|
||||
var filePath = Path.Combine(hostingEnvironment.ContentRootPath, folderName, fileName);
|
||||
|
||||
if (procedures == null || procedures.Count <= 0)
|
||||
{
|
||||
throw new Exception("Не выбраны процедуры!");
|
||||
}
|
||||
_reportLogic.SaveProcedureCosmeticsToWordFile(new ReportBindingModel
|
||||
{
|
||||
FileName = filePath,
|
||||
DateFrom = dateFrom,
|
||||
DateTo = dateTo
|
||||
});
|
||||
|
||||
_reportLogic.SaveProcedureCosmeticsToWordFile(new ReportBindingModel
|
||||
{
|
||||
FileName = $@"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\Downloads\Список процедур {DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")}.docx",
|
||||
DateFrom = dateFrom,
|
||||
DateTo = dateTo
|
||||
});
|
||||
// Возвращаем файл для загрузки
|
||||
var fileBytes = await System.IO.File.ReadAllBytesAsync(filePath);
|
||||
return File(fileBytes, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", fileName);
|
||||
}
|
||||
|
||||
Response.Redirect("/Home/Reports");
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> CreateReportExcel(List<int> procedures, DateTime dateFrom, DateTime dateTo, [FromServices] IWebHostEnvironment hostingEnvironment)
|
||||
{
|
||||
// Проверки ввода и авторизации
|
||||
var folderName = "C:\\отчеты";
|
||||
var fileName = $"Список процедур {DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")}.xlsx";
|
||||
var filePath = Path.Combine(hostingEnvironment.ContentRootPath, folderName, fileName);
|
||||
|
||||
[HttpPost]
|
||||
public void CreateReportExcel(List<int> procedures, DateTime dateFrom, DateTime dateTo)
|
||||
{
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
if (dateFrom == DateTime.MinValue || dateTo == DateTime.MinValue)
|
||||
{
|
||||
throw new Exception("Введены не все данные!");
|
||||
}
|
||||
_reportLogic.SaveProcedureCosmeticsToExcelFile(new ReportBindingModel
|
||||
{
|
||||
FileName = filePath,
|
||||
DateFrom = dateFrom,
|
||||
DateTo = dateTo
|
||||
});
|
||||
|
||||
if (procedures == null || procedures.Count <= 0)
|
||||
{
|
||||
throw new Exception("Не выбраны процедуры!");
|
||||
}
|
||||
// Возвращаем файл для загрузки
|
||||
var fileBytes = await System.IO.File.ReadAllBytesAsync(filePath);
|
||||
return File(fileBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", fileName);
|
||||
}
|
||||
|
||||
_reportLogic.SaveProcedureCosmeticsToExcelFile(new ReportBindingModel
|
||||
{
|
||||
FileName = $@"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\Downloads\Список процедур {DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")}.xlsx",
|
||||
DateFrom = dateFrom,
|
||||
DateTo = dateTo
|
||||
});
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> CreateReportPdf(DateTime dateFrom, DateTime dateTo, [FromServices] IWebHostEnvironment hostingEnvironment)
|
||||
{
|
||||
// Проверки авторизации и ввода
|
||||
var folderName = "C:\\отчеты";
|
||||
var fileName = $"Список заказов {DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")}.pdf";
|
||||
var filePath = Path.Combine(hostingEnvironment.ContentRootPath, folderName, fileName);
|
||||
|
||||
Response.Redirect("/Home/Reports");
|
||||
}
|
||||
_reportLogic.SaveOrdersToPdfFile(new ReportOrderBindingModel
|
||||
{
|
||||
FileName = filePath,
|
||||
DateFrom = dateFrom,
|
||||
DateTo = dateTo,
|
||||
WorkerId = APIWorker.Worker.Id
|
||||
});
|
||||
|
||||
[HttpPost]
|
||||
public void CreateReportPdf(DateTime dateFrom, DateTime dateTo)
|
||||
{
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
// Возвращаем файл для загрузки
|
||||
var fileBytes = await System.IO.File.ReadAllBytesAsync(filePath);
|
||||
return File(fileBytes, "application/pdf", fileName);
|
||||
}
|
||||
|
||||
if (dateFrom == DateTime.MinValue || dateTo == DateTime.MinValue)
|
||||
{
|
||||
throw new Exception("Введены не все данные!");
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> SendReport(IFormFile fileUpload, [FromServices] IWebHostEnvironment hostingEnvironment)
|
||||
{
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
|
||||
_reportLogic.SaveOrdersToPdfFile(new ReportOrderBindingModel
|
||||
{
|
||||
FileName = $@"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\Downloads\Список заказов{DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")}.xlsx",
|
||||
DateFrom = dateFrom,
|
||||
DateTo = dateTo,
|
||||
WorkerId = APIWorker.Worker.Id
|
||||
});
|
||||
if (fileUpload == null || fileUpload.Length <= 0)
|
||||
{
|
||||
throw new Exception("Файл не выбран или пуст!");
|
||||
}
|
||||
|
||||
Response.Redirect("/Home/Reports");
|
||||
}
|
||||
// Путь до файла
|
||||
var uploadPath = Path.Combine(hostingEnvironment.ContentRootPath, "C:\\отчеты");
|
||||
var fileName = Path.GetFileName(fileUpload.FileName);
|
||||
var fullPath = Path.Combine(uploadPath, fileName);
|
||||
|
||||
[HttpPost]
|
||||
public void SendReport(IFormFile fileUpload)
|
||||
{
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
using (var fileStream = new FileStream(fullPath, FileMode.Create))
|
||||
{
|
||||
await fileUpload.CopyToAsync(fileStream);
|
||||
}
|
||||
|
||||
if (fileUpload == null || fileUpload.Length <= 0)
|
||||
{
|
||||
throw new Exception("Файл не выбран или пуст!");
|
||||
}
|
||||
_mailLogic.MailSendAsync(new MailSendInfoBindingModel
|
||||
{
|
||||
MailAddress = APIWorker.Worker.Email,
|
||||
Subject = $"{fileName.Split('.')[0]}",
|
||||
Text = $"Отчёт отправлен {DateTime.Now}",
|
||||
Path = fullPath
|
||||
});
|
||||
|
||||
// Путь до файла
|
||||
var uploadPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads\";
|
||||
var fileName = Path.GetFileName(fileUpload.FileName);
|
||||
var fullPath = Path.Combine(uploadPath, fileName);
|
||||
return RedirectToAction("Reports", "Home");
|
||||
}
|
||||
|
||||
_mailLogic.MailSendAsync(new MailSendInfoBindingModel
|
||||
{
|
||||
MailAddress = APIWorker.Worker.Email,
|
||||
Subject = $"{fileName.Split('.')[0]}",
|
||||
Text = $"Отчёт отправлен {DateTime.Now}",
|
||||
Path = fullPath
|
||||
});
|
||||
|
||||
Response.Redirect("/Home/Reports");
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
|
Loading…
Reference in New Issue
Block a user