69 lines
1.7 KiB
C#
69 lines
1.7 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;
|
|
|
|
public VisitorController(IVisitorLogic logic, ILogger<VisitorController> logger)
|
|
{
|
|
_logger = logger;
|
|
_logic = logic;
|
|
}
|
|
|
|
[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;
|
|
}
|
|
}
|
|
}
|
|
}
|