2024-05-27 07:56:21 +04:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using BankContracts.BindingModels;
|
2024-05-02 00:46:24 +04:00
|
|
|
|
using BankContracts.BusinessLogicsContracts;
|
|
|
|
|
using BankContracts.SearchModels;
|
|
|
|
|
using BankContracts.ViewModels;
|
|
|
|
|
using BankDatabaseImplement.Models;
|
|
|
|
|
|
|
|
|
|
namespace BankRestApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class DepositController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
2024-05-27 07:56:21 +04:00
|
|
|
|
private readonly IDepositLogic _deposit;
|
|
|
|
|
public DepositController(ILogger<DepositController> logger, IDepositLogic deposit)
|
2024-05-02 00:46:24 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
2024-05-27 07:56:21 +04:00
|
|
|
|
_deposit = deposit;
|
2024-05-02 00:46:24 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2024-05-27 07:56:21 +04:00
|
|
|
|
public Tuple<DepositViewModel, List<Tuple<string, string>>>? GetDeposit(int depositId)
|
2024-05-02 00:46:24 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-05-27 07:56:21 +04:00
|
|
|
|
var elem = _deposit.ReadElement(new DepositSearchModel { Id = depositId });
|
|
|
|
|
if (elem == null)
|
|
|
|
|
return null;
|
|
|
|
|
var res = Tuple.Create(elem, elem.ClientDeposits.Select(x => Tuple.Create(x.Value.ClientSurname, x.Value.Snils)).ToList());
|
|
|
|
|
res.Item1.ClientDeposits = null!;
|
|
|
|
|
return res;
|
2024-05-02 00:46:24 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-05-27 07:56:21 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка получения вклада по id={Id}", depositId);
|
2024-05-02 00:46:24 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-27 07:56:21 +04:00
|
|
|
|
|
2024-05-02 00:46:24 +04:00
|
|
|
|
[HttpGet]
|
2024-05-27 07:56:21 +04:00
|
|
|
|
public List<DepositViewModel>? GetDepositList(int? workerId = null)
|
2024-05-02 00:46:24 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-05-27 07:56:21 +04:00
|
|
|
|
List<DepositViewModel> res;
|
|
|
|
|
if (!workerId.HasValue)
|
|
|
|
|
res = _deposit.ReadList(null);
|
|
|
|
|
else
|
|
|
|
|
res = _deposit.ReadList(new DepositSearchModel { WorkerId = workerId });
|
|
|
|
|
foreach (var deposit in res)
|
|
|
|
|
deposit.ClientDeposits = null;
|
|
|
|
|
return res;
|
2024-05-02 00:46:24 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-05-27 07:56:21 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка вкладов");
|
2024-05-02 00:46:24 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
2024-05-27 07:56:21 +04:00
|
|
|
|
public bool CreateDeposit(DepositBindingModel model)
|
2024-05-02 00:46:24 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-05-27 07:56:21 +04:00
|
|
|
|
return _deposit.Create(model);
|
2024-05-02 00:46:24 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-05-27 07:56:21 +04:00
|
|
|
|
_logger.LogError(ex, "Не удалось создать вклад");
|
2024-05-02 00:46:24 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-27 07:56:21 +04:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public bool UpdateDeposit(bool isConnection, DepositBindingModel model)
|
2024-05-02 00:46:24 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-05-27 07:56:21 +04:00
|
|
|
|
if (!isConnection)
|
|
|
|
|
model.ClientDeposit = null!;
|
|
|
|
|
return _deposit.Update(model);
|
2024-05-02 00:46:24 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-05-27 07:56:21 +04:00
|
|
|
|
_logger.LogError(ex, "Не удалось обновить вклад");
|
2024-05-02 00:46:24 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-27 07:56:21 +04:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public bool DeleteDeposit(DepositBindingModel model)
|
2024-05-02 00:46:24 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-05-27 07:56:21 +04:00
|
|
|
|
return _deposit.Delete(model);
|
2024-05-02 00:46:24 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка удаления вклада");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-27 07:56:21 +04:00
|
|
|
|
}
|