93 lines
2.6 KiB
C#
93 lines
2.6 KiB
C#
using CanteenContracts.BindingModels;
|
|
using CanteenContracts.BusinessLogicsContracts;
|
|
using CanteenContracts.SearchModel;
|
|
using CanteenContracts.View;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace CanteenRestApi.Controllers
|
|
{
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class VisitorController : Controller
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IVisitorLogic _logic;
|
|
private readonly IReportLogic _report;
|
|
|
|
public VisitorController(IVisitorLogic logic, IReportLogic report, ILogger<VisitorController> logger)
|
|
{
|
|
_logger = logger;
|
|
_logic = logic;
|
|
_report = report;
|
|
}
|
|
|
|
[HttpGet]
|
|
public VisitorViewModel? Login(string login, string password)
|
|
{
|
|
try
|
|
{
|
|
return _logic.ReadElement(new VisitorSearchModel
|
|
{
|
|
Login = login,
|
|
Password = password
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during logging in");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Register(VisitorBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Create(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during registration");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void UpdateData(VisitorBindingModel 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.saveLunchesToPdfFile(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;
|
|
}
|
|
}
|
|
}
|
|
}
|