77 lines
2.4 KiB
C#
77 lines
2.4 KiB
C#
using BankYouBankruptContracts.BusinessLogicsContracts;
|
||
using BlacksmithWorkshopContracts.BindingModels;
|
||
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
|
||
using BlacksmithWorkshopContracts.SearchModels;
|
||
using BlacksmithWorkshopContracts.ViewModels;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
|
||
namespace BlacksmithWorkshopRestApi.Controllers
|
||
{
|
||
//указание у контроллера, что Route будет строиться не только по наванию контроллера, но и по названию метода (так как у нас два Post-метода)
|
||
[Route("api/[controller]/[action]")]
|
||
[ApiController]
|
||
public class ClientController : Controller
|
||
{
|
||
private readonly ILogger _logger;
|
||
|
||
private readonly IClientLogic _clientLogic;
|
||
|
||
private readonly ICashierLogic _cashierLogic;
|
||
|
||
public ClientController(IClientLogic logic, ILogger<ClientController> logger)
|
||
{
|
||
_logger = logger;
|
||
_logic = logic;
|
||
}
|
||
|
||
[HttpGet]
|
||
public ClientViewModel? Login(string login, string password)
|
||
{
|
||
try
|
||
{
|
||
//попытка найти запись по переданным логину и паролю
|
||
return _logic.ReadElement(new ClientSearchModel
|
||
{
|
||
Email = login,
|
||
Password = password
|
||
});
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка входа в систему");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
[HttpPost]
|
||
public void Register(ClientBindingModel model)
|
||
{
|
||
try
|
||
{
|
||
//создание клиента
|
||
_logic.Create(model);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка регистрации");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
[HttpPost]
|
||
public void UpdateData(ClientBindingModel model)
|
||
{
|
||
try
|
||
{
|
||
//изменение клиента
|
||
_logic.Update(model);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка обновления данных");
|
||
throw;
|
||
}
|
||
}
|
||
}
|
||
}
|