PIbd-23_Elatomtsev_L.K._Cou.../Bank/BankRestApi/Controllers/RefillController.cs

100 lines
2.7 KiB
C#
Raw Permalink Normal View History

2024-05-27 07:56:21 +04:00
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using BankContracts.BindingModels;
using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels;
using BankContracts.ViewModels;
using BankDatabaseImplement.Models;
namespace BankRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class RefillController : Controller
{
private readonly ILogger _logger;
2024-05-27 07:56:21 +04:00
private readonly IRefillLogic _refill;
public RefillController(ILogger<RefillController> logger, IRefillLogic refill)
{
_logger = logger;
2024-05-27 07:56:21 +04:00
_refill = refill;
}
[HttpGet]
2024-05-27 07:56:21 +04:00
public RefillViewModel GetRefill(int refillId)
{
try
{
2024-05-27 07:56:21 +04:00
var elem = _refill.ReadElement(new RefillSearchModel { Id = refillId });
return elem;
}
catch (Exception ex)
{
2024-05-27 07:56:21 +04:00
_logger.LogError(ex, "Ошибка получения поплнения по id={Id}", refillId);
throw;
}
}
2024-05-27 07:56:21 +04:00
[HttpGet]
2024-05-27 07:56:21 +04:00
public List<RefillViewModel>? GetRefills(int? workerld)
{
try
{
2024-05-27 07:56:21 +04:00
if (!workerld.HasValue)
return _refill.ReadList(null);
return _refill.ReadList(new RefillSearchModel
{
2024-05-27 07:56:21 +04:00
WorkerId = workerld
});
}
catch (Exception ex)
{
2024-05-27 07:56:21 +04:00
_logger.LogError(ex, "Ошибка получения списка пополнений пользователя id ={ Id}", workerld);
throw;
}
}
2024-05-27 07:56:21 +04:00
[HttpPost]
public void CreateRefill(RefillBindingModel model)
{
try
{
2024-05-27 07:56:21 +04:00
_refill.Create(model);
}
catch (Exception ex)
{
2024-05-27 07:56:21 +04:00
_logger.LogError(ex, "Ошибка создания прививки");
throw;
}
}
2024-05-27 07:56:21 +04:00
[HttpPost]
public bool UpdateRefill(RefillBindingModel model)
{
try
{
2024-05-27 07:56:21 +04:00
return _refill.Update(model);
}
catch (Exception ex)
{
2024-05-27 07:56:21 +04:00
_logger.LogError(ex, "Не удалось обновить привику");
throw;
}
}
2024-05-27 07:56:21 +04:00
[HttpPost]
public bool DeleteRefill(RefillBindingModel model)
{
try
{
2024-05-27 07:56:21 +04:00
return _refill.Delete(model);
}
catch (Exception ex)
{
2024-05-27 07:56:21 +04:00
_logger.LogError(ex, "Ошибка удаления привики");
throw;
}
}
}
2024-05-27 07:56:21 +04:00
}