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-17 14:27:46 +04:00
|
|
|
|
private readonly IDebitingLogic _debitingLogic;
|
2023-05-17 15:18:35 +04:00
|
|
|
|
private readonly ICreditingLogic _creditingLogic;
|
2023-05-17 14:27:46 +04:00
|
|
|
|
|
2023-05-17 15:18:35 +04:00
|
|
|
|
public ClientController(ILogger<ClientController> logger,
|
|
|
|
|
IClientLogic clientLogic, IDebitingLogic debitingLogic, ICreditingLogic creditingLogic)
|
2023-04-01 23:47:54 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
2023-05-14 12:59:47 +04:00
|
|
|
|
_clientLogic = clientLogic;
|
2023-05-17 14:27:46 +04:00
|
|
|
|
_debitingLogic = debitingLogic;
|
2023-05-17 15:18:35 +04:00
|
|
|
|
_creditingLogic = creditingLogic;
|
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-05-16 20:05:59 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public ClientViewModel? GetClient(int clientId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _clientLogic.ReadElement(new ClientSearchModel { Id = clientId });
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-17 14:27:46 +04:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<DebitingViewModel>? getUsersDebitings(int userId) {
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _debitingLogic.ReadList(new DebitingSearchModel()
|
|
|
|
|
{
|
|
|
|
|
UserId = userId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения пользователей");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-17 15:18:35 +04:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<CreditingViewModel>? getUsersCreditings(int userId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _creditingLogic.ReadList(new CreditingSearchModel()
|
|
|
|
|
{
|
|
|
|
|
UserId = userId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения пользователей");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-01 23:47:54 +04:00
|
|
|
|
}
|
|
|
|
|
}
|