100 lines
2.7 KiB
C#
100 lines
2.7 KiB
C#
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;
|
||
private readonly IRefillLogic _refill;
|
||
|
||
public RefillController(ILogger<RefillController> logger, IRefillLogic refill)
|
||
{
|
||
_logger = logger;
|
||
_refill = refill;
|
||
}
|
||
[HttpGet]
|
||
public RefillViewModel GetRefill(int refillId)
|
||
{
|
||
try
|
||
{
|
||
var elem = _refill.ReadElement(new RefillSearchModel { Id = refillId });
|
||
return elem;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка получения поплнения по id={Id}", refillId);
|
||
throw;
|
||
}
|
||
}
|
||
|
||
[HttpGet]
|
||
public List<RefillViewModel>? GetRefills(int? workerld)
|
||
{
|
||
try
|
||
{
|
||
if (!workerld.HasValue)
|
||
return _refill.ReadList(null);
|
||
return _refill.ReadList(new RefillSearchModel
|
||
{
|
||
WorkerId = workerld
|
||
});
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка получения списка пополнений пользователя id ={ Id}", workerld);
|
||
throw;
|
||
}
|
||
}
|
||
|
||
[HttpPost]
|
||
public void CreateRefill(RefillBindingModel model)
|
||
{
|
||
try
|
||
{
|
||
_refill.Create(model);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка создания прививки");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
[HttpPost]
|
||
public bool UpdateRefill(RefillBindingModel model)
|
||
{
|
||
try
|
||
{
|
||
return _refill.Update(model);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Не удалось обновить привику");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
[HttpPost]
|
||
public bool DeleteRefill(RefillBindingModel model)
|
||
{
|
||
try
|
||
{
|
||
return _refill.Delete(model);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка удаления привики");
|
||
throw;
|
||
}
|
||
}
|
||
}
|
||
}
|