2023-05-25 20:53:47 +04:00
|
|
|
|
using CarServiceContracts.BindingModels;
|
|
|
|
|
using CarServiceContracts.BusinessLogicsContracts;
|
|
|
|
|
using CarServiceWebApp.Models;
|
2023-05-25 22:31:46 +04:00
|
|
|
|
using log4net;
|
2023-05-25 20:53:47 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace CarServiceWebApp.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class ReportController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly IReportLogic _reportLogic;
|
|
|
|
|
private readonly IWorkLogic _workLogic;
|
|
|
|
|
private static List<int> SelectedWorks = new();
|
|
|
|
|
private static ReportBindingModel PaymentsModel = new();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ReportController(IReportLogic reportLogic, IWorkLogic workLogic)
|
|
|
|
|
{
|
|
|
|
|
_reportLogic = reportLogic;
|
|
|
|
|
_workLogic = workLogic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
if (CurrentUser.UserId < 1)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
public IActionResult ReportRequestsByWorks()
|
|
|
|
|
{
|
|
|
|
|
if (CurrentUser.UserId < 1)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
var requestsByWorks = _reportLogic.GetRequestsByWorks(new() { SelectedWorks = SelectedWorks } );
|
|
|
|
|
ViewBag.RequestsByWorks = requestsByWorks;
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult WorksSelection()
|
|
|
|
|
{
|
|
|
|
|
if (CurrentUser.UserId < 1)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
var works = _workLogic.ReadList(new() { Id = CurrentUser.UserId});
|
|
|
|
|
ViewBag.Works = works;
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult WorksSelection(List<int> selwor)
|
|
|
|
|
{
|
|
|
|
|
SelectedWorks = selwor;
|
|
|
|
|
return Redirect("~/Report/ReportRequestsByWorks");
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult DateSelection()
|
|
|
|
|
{
|
|
|
|
|
if (CurrentUser.UserId < 1)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult DateSelection(DateTime dateFrom, DateTime dateTo)
|
|
|
|
|
{
|
|
|
|
|
PaymentsModel = new() { DateFrom = dateFrom, DateTo = dateTo };
|
|
|
|
|
return Redirect("~/Report/ReportPayments");
|
|
|
|
|
}
|
|
|
|
|
public IActionResult ReportPayments()
|
|
|
|
|
{
|
|
|
|
|
var payments = _reportLogic.GetPayments(PaymentsModel);
|
|
|
|
|
ViewBag.Payments = payments;
|
|
|
|
|
return View();
|
|
|
|
|
}
|
2023-05-25 22:31:46 +04:00
|
|
|
|
public IActionResult SaveToWord()
|
|
|
|
|
{
|
2023-05-25 23:14:32 +04:00
|
|
|
|
_reportLogic.SaveRequestsToWordFile(new ReportBindingModel { SelectedWorks = SelectedWorks, FileName = "C:\\Users\\igors\\source\\repos\\ISEbd-21_Melnikov_I.O._CarService\\CarService\\CarServiceWebApp\\Files\\ReportWord.docx" });
|
2023-05-25 22:31:46 +04:00
|
|
|
|
return Redirect("~/Report/DownLoadWord");
|
|
|
|
|
}
|
|
|
|
|
public IActionResult DownLoadWord()
|
|
|
|
|
{
|
|
|
|
|
string filePath = "C:\\Users\\igors\\source\\repos\\ISEbd-21_Melnikov_I.O._CarService\\CarService\\CarServiceWebApp\\Files\\ReportWord.docx";
|
|
|
|
|
string fileName = "Отчет.docx";
|
|
|
|
|
|
|
|
|
|
byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
|
|
|
|
|
|
2023-05-25 23:14:32 +04:00
|
|
|
|
return File(fileBytes, "application/force-download", fileName);
|
|
|
|
|
}
|
|
|
|
|
public IActionResult SaveToExcel()
|
|
|
|
|
{
|
|
|
|
|
_reportLogic.SaveRequestsToExcelFile(new ReportBindingModel { SelectedWorks = SelectedWorks, FileName = "C:\\Users\\igors\\source\\repos\\ISEbd-21_Melnikov_I.O._CarService\\CarService\\CarServiceWebApp\\Files\\ReportExcel.xlsx" });
|
|
|
|
|
return Redirect("~/Report/DownLoadExcel");
|
|
|
|
|
}
|
|
|
|
|
public IActionResult DownLoadExcel()
|
|
|
|
|
{
|
|
|
|
|
string filePath = "C:\\Users\\igors\\source\\repos\\ISEbd-21_Melnikov_I.O._CarService\\CarService\\CarServiceWebApp\\Files\\ReportExcel.xlsx";
|
|
|
|
|
string fileName = "Отчет.xlsx";
|
|
|
|
|
|
|
|
|
|
byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
|
|
|
|
|
|
2023-05-25 22:31:46 +04:00
|
|
|
|
return File(fileBytes, "application/force-download", fileName);
|
|
|
|
|
}
|
2023-05-25 20:53:47 +04:00
|
|
|
|
}
|
|
|
|
|
}
|