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 RefillController : Controller
|
|||
|
{
|
|||
|
private readonly ILogger _logger;
|
|||
|
private readonly IRefillLogic _logic;
|
|||
|
public RefillController(ILogger<RefillController> logger,
|
|||
|
IRefillLogic logic)
|
|||
|
{
|
|||
|
_logger = logger;
|
|||
|
_logic = logic;
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public List<RefillViewModel>? GetRefillList()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
return _logic.ReadList(null);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка получения списка пополнений");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
[HttpGet]
|
|||
|
public RefillViewModel? GetRefill(int RefillId)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
return _logic.ReadElement(new RefillSearchModel
|
|||
|
{
|
|||
|
Id = RefillId
|
|||
|
});
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(
|
|||
|
ex, "Ошибка получения пополнения по Id={Id}",
|
|||
|
RefillId);
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
[HttpPost]
|
|||
|
public void CreateRefill(RefillBindingModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
_logic.Create(model);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка создания пополнения");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
[HttpPut]
|
|||
|
public void UpdateRefill(RefillBindingModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
_logic.Update(model);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка обновления пополнения");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
[HttpDelete]
|
|||
|
public void DeleteRefill(RefillBindingModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
_logic.Delete(model);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка удаления пополнения");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|