2023-05-14 09:32:18 +04:00
|
|
|
|
using BankYouBankruptBusinessLogic.BusinessLogics;
|
|
|
|
|
using BankYouBankruptContracts.BindingModels;
|
2023-05-14 12:59:47 +04:00
|
|
|
|
using BankYouBankruptContracts.BusinessLogicsContracts;
|
|
|
|
|
using BankYouBankruptContracts.SearchModels;
|
|
|
|
|
using BankYouBankruptContracts.ViewModels;
|
2023-05-14 09:32:18 +04:00
|
|
|
|
using DocumentFormat.OpenXml.Office2010.Excel;
|
2023-04-01 23:47:54 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
2023-05-14 12:59:47 +04:00
|
|
|
|
namespace BankYouBankruptRestApi.Controllers
|
2023-04-01 23:47:54 +04:00
|
|
|
|
{
|
|
|
|
|
//указание у контроллера, что Route будет строиться не только по наванию контроллера, но и по названию метода (так как у нас два Post-метода)
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class ClientController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
2023-04-02 01:17:44 +04:00
|
|
|
|
private readonly IClientLogic _clientLogic;
|
|
|
|
|
|
2023-05-14 12:59:47 +04:00
|
|
|
|
public ClientController(IClientLogic clientLogic, ILogger<ClientController> logger)
|
2023-04-01 23:47:54 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
2023-05-14 12:59:47 +04:00
|
|
|
|
_clientLogic = clientLogic;
|
2023-04-01 23:47:54 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public ClientViewModel? Login(string login, string password)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//попытка найти запись по переданным логину и паролю
|
2023-05-14 12:59:47 +04:00
|
|
|
|
return _clientLogic.ReadElement(new ClientSearchModel
|
2023-04-01 23:47:54 +04:00
|
|
|
|
{
|
|
|
|
|
Email = login,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-14 09:32:18 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<ClientViewModel>? GetAllClients() {
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _clientLogic.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения пользователей");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-01 23:47:54 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Register(ClientBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//создание клиента
|
2023-05-14 12:59:47 +04:00
|
|
|
|
_clientLogic.Create(model);
|
2023-04-01 23:47:54 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка регистрации");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateData(ClientBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//изменение клиента
|
2023-05-14 12:59:47 +04:00
|
|
|
|
_clientLogic.Update(model);
|
2023-04-01 23:47:54 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка обновления данных");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|