PIbd-21_BatylkinaAO_MusoevD.../Canteen/CanteenRestApi/Controllers/ManagerController.cs
2023-06-21 19:25:26 +04:00

94 lines
2.6 KiB
C#

using CanteenContracts.BindingModels;
using CanteenContracts.BusinessLogicsContracts;
using CanteenContracts.SearchModel;
using CanteenContracts.View;
using Microsoft.AspNetCore.Mvc;
using System.IO.Pipes;
namespace CanteenRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ManagerController : Controller
{
private readonly ILogger _logger;
private readonly IManagerLogic _logic;
private readonly IReportLogic _report;
public ManagerController(IManagerLogic logic, IReportLogic report, ILogger<ManagerController> logger)
{
_logger = logger;
_logic = logic;
_report = report;
}
[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;
}
}
[HttpPost]
public void SendEmail(MailSendInfoBindingModel emailInfo)
{
try
{
string path = $"C:\\PdfReports\\{DateTime.Now.ToString("HH.mm.ss_dd.MM.yyyy")}.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;
}
}
}
}