2023-05-16 19:13:19 +04:00
|
|
|
|
using CanteenContracts.BindingModels;
|
|
|
|
|
using CanteenContracts.BusinessLogicsContracts;
|
|
|
|
|
using CanteenContracts.SearchModel;
|
|
|
|
|
using CanteenContracts.View;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-06-19 09:12:18 +04:00
|
|
|
|
using System.IO.Pipes;
|
2023-05-16 19:13:19 +04:00
|
|
|
|
|
|
|
|
|
namespace CanteenRestApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class ManagerController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IManagerLogic _logic;
|
2023-06-19 09:12:18 +04:00
|
|
|
|
private readonly IReportLogic _report;
|
2023-05-16 19:13:19 +04:00
|
|
|
|
|
2023-06-19 09:12:18 +04:00
|
|
|
|
public ManagerController(IManagerLogic logic, IReportLogic report, ILogger<ManagerController> logger)
|
2023-05-16 19:13:19 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_logic = logic;
|
2023-06-19 09:12:18 +04:00
|
|
|
|
_report = report;
|
2023-05-16 19:13:19 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public ManagerViewModel? Login(string login, string password)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _logic.ReadElement(new ManagerSearchModel
|
|
|
|
|
{
|
|
|
|
|
Login = login,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Error during logging in");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Register(ManagerBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logic.Create(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Error during registration");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateData(ManagerBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logic.Update(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Error during updating");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-19 09:12:18 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void SendEmail(MailSendInfoBindingModel emailInfo)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string path = $"C:\\PdfReports\\{DateTime.Now.ToString("HH.mm.ss_dd.MM.yyyy")}111111.pdf";
|
|
|
|
|
_report.saveCooksToPdfFile(new ReportBindingModel
|
|
|
|
|
{
|
|
|
|
|
FileName = path,
|
|
|
|
|
UserId = emailInfo.report.UserId,
|
|
|
|
|
DateBefore = emailInfo.report.DateBefore,
|
|
|
|
|
DateAfter = emailInfo.report.DateAfter
|
|
|
|
|
});
|
|
|
|
|
emailInfo.Path = path;
|
|
|
|
|
_logic.SendMail(emailInfo);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Error during updating");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-16 19:13:19 +04:00
|
|
|
|
}
|
|
|
|
|
}
|