146 lines
4.5 KiB
C#
146 lines
4.5 KiB
C#
using BankYouBankruptBusinessLogic.BusinessLogics;
|
||
using BankYouBankruptContracts.BindingModels;
|
||
using BankYouBankruptContracts.BusinessLogicsContracts;
|
||
using BankYouBankruptContracts.SearchModels;
|
||
using BankYouBankruptContracts.ViewModels.Client.Default;
|
||
using BankYouBankruptContracts.ViewModels.Client.Diagram;
|
||
using DocumentFormat.OpenXml.Office2010.Excel;
|
||
using DocumentFormat.OpenXml.Spreadsheet;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
|
||
namespace BankYouBankruptRestApi.Controllers
|
||
{
|
||
//указание у контроллера, что Route будет строиться не только по наванию контроллера, но и по названию метода (так как у нас два Post-метода)
|
||
[Route("api/[controller]/[action]")]
|
||
[ApiController]
|
||
public class ClientController : Controller
|
||
{
|
||
private readonly ILogger _logger;
|
||
|
||
private readonly IClientLogic _clientLogic;
|
||
|
||
private readonly IDebitingLogic _debitingLogic;
|
||
private readonly ICreditingLogic _creditingLogic;
|
||
|
||
public ClientController(ILogger<ClientController> logger,
|
||
IClientLogic clientLogic, IDebitingLogic debitingLogic, ICreditingLogic creditingLogic)
|
||
{
|
||
_logger = logger;
|
||
_clientLogic = clientLogic;
|
||
_debitingLogic = debitingLogic;
|
||
_creditingLogic = creditingLogic;
|
||
}
|
||
|
||
[HttpGet]
|
||
public ClientViewModel? Login(string login, string password)
|
||
{
|
||
try
|
||
{
|
||
//попытка найти запись по переданным логину и паролю
|
||
return _clientLogic.ReadElement(new ClientSearchModel
|
||
{
|
||
Email = login,
|
||
Password = password
|
||
});
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка входа в систему");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
[HttpGet]
|
||
public List<ClientViewModel>? GetAllClients() {
|
||
try
|
||
{
|
||
return _clientLogic.ReadList(null);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка получения пользователей");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
[HttpGet]
|
||
public ClientViewModel? GetClient(int clientId)
|
||
{
|
||
try
|
||
{
|
||
return _clientLogic.ReadElement(new ClientSearchModel { Id = clientId });
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка получения пользователя");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
[HttpPost]
|
||
public void Register(ClientBindingModel model)
|
||
{
|
||
try
|
||
{
|
||
//создание клиента
|
||
_clientLogic.Create(model);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка регистрации");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
[HttpPost]
|
||
public void UpdateData(ClientBindingModel model)
|
||
{
|
||
try
|
||
{
|
||
//изменение клиента
|
||
_clientLogic.Update(model);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка обновления данных");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
[HttpGet]
|
||
public List<DebitingViewModel>? getUsersDebitings(int userId) {
|
||
try
|
||
{
|
||
return _debitingLogic.ReadList(new DebitingSearchModel()
|
||
{
|
||
UserId = userId
|
||
});
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка получения пользователей");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
[HttpGet]
|
||
public List<CreditingViewModel>? getUsersCreditings(int userId)
|
||
{
|
||
try
|
||
{
|
||
return _creditingLogic.ReadList(new CreditingSearchModel()
|
||
{
|
||
UserId = userId
|
||
});
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка получения пользователей");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
}
|