94 lines
2.5 KiB
C#
94 lines
2.5 KiB
C#
|
using BankContracts.BindingModels;
|
|||
|
using BankContracts.BusinessLogicsContracts;
|
|||
|
using BankContracts.SearchModels;
|
|||
|
using BankContracts.ViewModels;
|
|||
|
using BankDatabaseImplement.Models;
|
|||
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
|||
|
namespace BankRestApi.Controllers
|
|||
|
{
|
|||
|
[Route("api/[controller]/[action]")]
|
|||
|
[ApiController]
|
|||
|
public class DepositController : Controller
|
|||
|
{
|
|||
|
private readonly ILogger _logger;
|
|||
|
private readonly IDepositLogic _logic;
|
|||
|
public DepositController(ILogger<DepositController> logger,
|
|||
|
IDepositLogic logic)
|
|||
|
{
|
|||
|
_logger = logger;
|
|||
|
_logic = logic;
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public List<DepositViewModel>? GetDepositList()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
return _logic.ReadList(null);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка получения списка вкладов");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
[HttpGet]
|
|||
|
public DepositViewModel? GetDeposit(int DepositId)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
return _logic.ReadElement(new DepositSearchModel
|
|||
|
{
|
|||
|
Id = DepositId
|
|||
|
});
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(
|
|||
|
ex, "Ошибка получения вклада по Id={Id}",
|
|||
|
DepositId);
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
[HttpPost]
|
|||
|
public void CreateDeposit(DepositBindingModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
_logic.Create(model);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка создания вклада");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
[HttpPut]
|
|||
|
public void UpdateDeposit(DepositBindingModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
_logic.Update(model);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка обновления вклада");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
[HttpDelete]
|
|||
|
public void DeleteDeposit(DepositBindingModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
_logic.Delete(model);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка удаления вклада");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|