2023-05-14 12:59:47 +04:00
|
|
|
|
using BankYouBankruptContracts.BindingModels;
|
|
|
|
|
using BankYouBankruptContracts.BusinessLogicsContracts;
|
|
|
|
|
using BankYouBankruptContracts.SearchModels;
|
|
|
|
|
using BankYouBankruptContracts.ViewModels;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace BankYouBankruptRestApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
//указание у контроллера, что Route будет строиться не только по наванию контроллера, но и по названию метода (так как у нас два Post-метода)
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class CashierController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
2023-05-14 13:33:43 +04:00
|
|
|
|
private readonly ICashierLogic _cashierLogic;
|
2023-05-14 12:59:47 +04:00
|
|
|
|
|
2023-05-14 13:33:43 +04:00
|
|
|
|
public CashierController(ICashierLogic cashierLogic, ILogger<AccountController> logger)
|
2023-05-14 12:59:47 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_cashierLogic = cashierLogic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public CashierViewModel? Login(string login, string password)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//попытка найти запись по переданным логину и паролю
|
|
|
|
|
return _cashierLogic.ReadElement(new CashierSearchModel
|
|
|
|
|
{
|
|
|
|
|
Email = login,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 00:06:05 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public CashierViewModel? GetCashier(int id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//попытка найти запись по переданным логину и паролю
|
|
|
|
|
return _cashierLogic.ReadElement(new CashierSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2023-05-14 12:59:47 +04:00
|
|
|
|
public void Register(CashierBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//создание клиента
|
|
|
|
|
_cashierLogic.Create(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка регистрации");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateData(CashierBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//изменение клиента
|
|
|
|
|
_cashierLogic.Update(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка обновления данных");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|