ISEbd-21.Gordeev.I.V.SushiB.../SushiBar/SushiBarRestApi/Controllers/ClientController.cs

69 lines
2.0 KiB
C#
Raw Normal View History

2024-05-01 10:50:16 +04:00
using Microsoft.AspNetCore.Mvc;
using SushiBarContracts.BindingModel;
2024-04-25 13:16:23 +04:00
using SushiBarContracts.BusinessLogicsContracts;
2024-05-01 10:50:16 +04:00
using SushiBarContracts.SearchModel;
2024-04-25 13:16:23 +04:00
using SushiBarContracts.ViewModels;
2024-05-12 19:04:40 +04:00
2024-04-25 13:16:23 +04:00
namespace SushiBarRestApi.Controllers
{
2024-05-12 19:04:40 +04:00
[Route("api/[controller]/[action]")]
[ApiController]
public class ClientController : Controller
2024-04-25 13:16:23 +04:00
{
2024-05-12 19:04:40 +04:00
private readonly ILogger _logger;
private readonly IClientLogic _logic;
public ClientController(IClientLogic logic, ILogger<ClientController>
logger)
2024-04-25 13:16:23 +04:00
{
2024-05-12 19:04:40 +04:00
_logger = logger;
_logic = logic;
2024-04-25 13:16:23 +04:00
}
2024-05-12 19:04:40 +04:00
[HttpGet]
public ClientViewModel? Login(string login, string password)
2024-04-25 13:16:23 +04:00
{
2024-05-12 19:04:40 +04:00
try
{
return _logic.ReadElement(new ClientSearchModel
{
Email = login,
Password = password
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка входа в систему");
throw;
}
2024-04-25 13:16:23 +04:00
}
2024-05-12 19:04:40 +04:00
[HttpPost]
public void Register(ClientBindingModel model)
2024-04-25 13:16:23 +04:00
{
2024-05-12 19:04:40 +04:00
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка регистрации");
throw;
}
2024-04-25 13:16:23 +04:00
}
2024-05-12 19:04:40 +04:00
[HttpPost]
public void UpdateData(ClientBindingModel model)
2024-04-25 13:16:23 +04:00
{
2024-05-12 19:04:40 +04:00
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления данных");
throw;
}
2024-04-25 13:16:23 +04:00
}
2024-05-12 19:04:40 +04:00
2024-04-25 13:16:23 +04:00
}
}
2024-05-12 19:04:40 +04:00