91 lines
2.5 KiB
C#
91 lines
2.5 KiB
C#
|
using BankContracts.BindingModels;
|
|||
|
using BankContracts.BusinessLogicsContracts;
|
|||
|
using BankContracts.SearchModels;
|
|||
|
using BankContracts.ViewModels;
|
|||
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
|||
|
namespace BankRestApi.Controllers
|
|||
|
{
|
|||
|
[Route("api/[controller]/[action]")]
|
|||
|
[ApiController]
|
|||
|
public class TransferController : Controller
|
|||
|
{
|
|||
|
private readonly ILogger _logger;
|
|||
|
private readonly ITransferLogic _transfer;
|
|||
|
|
|||
|
public TransferController(ILogger<TransferController> logger, ITransferLogic transfer)
|
|||
|
{
|
|||
|
_logger = logger;
|
|||
|
_transfer = transfer;
|
|||
|
}
|
|||
|
[HttpGet]
|
|||
|
public List<TransferViewModel>? GetTransfersList()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
return _transfer.ReadList(null);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка получения списка зачислений");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public List<TransferViewModel>? GetTransfers(int operatorId)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
return _transfer.ReadList(new TransferSearchModel { OperatorId = operatorId });
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка получения списка зачислений оператора id={Id}", operatorId);
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost]
|
|||
|
public void CreateTransfer(TransferBindingModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
_transfer.Create(model);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка создания зачисления");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpPatch]
|
|||
|
public void UpdateTransfer(TransferBindingModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
_transfer.Update(model);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка обновления зачисления");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
[HttpDelete]
|
|||
|
public void DeleteTransfer(TransferBindingModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
_transfer.Delete(model);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка удаления зачисления");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|