2024-05-27 07:56:21 +04:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using BankContracts.BindingModels;
|
2024-05-02 00:46:24 +04:00
|
|
|
|
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)
|
2024-05-02 00:46:24 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
2024-05-27 07:56:21 +04:00
|
|
|
|
_refill = refill;
|
2024-05-02 00:46:24 +04:00
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
2024-05-27 07:56:21 +04:00
|
|
|
|
public RefillViewModel GetRefill(int refillId)
|
2024-05-02 00:46:24 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-05-27 07:56:21 +04:00
|
|
|
|
var elem = _refill.ReadElement(new RefillSearchModel { Id = refillId });
|
|
|
|
|
return elem;
|
2024-05-02 00:46:24 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-05-27 07:56:21 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка получения поплнения по id={Id}", refillId);
|
2024-05-02 00:46:24 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-27 07:56:21 +04:00
|
|
|
|
|
2024-05-02 00:46:24 +04:00
|
|
|
|
[HttpGet]
|
2024-05-27 07:56:21 +04:00
|
|
|
|
public List<RefillViewModel>? GetRefills(int? workerld)
|
2024-05-02 00:46:24 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-05-27 07:56:21 +04:00
|
|
|
|
if (!workerld.HasValue)
|
|
|
|
|
return _refill.ReadList(null);
|
|
|
|
|
return _refill.ReadList(new RefillSearchModel
|
2024-05-02 00:46:24 +04:00
|
|
|
|
{
|
2024-05-27 07:56:21 +04:00
|
|
|
|
WorkerId = workerld
|
2024-05-02 00:46:24 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-05-27 07:56:21 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка пополнений пользователя id ={ Id}", workerld);
|
2024-05-02 00:46:24 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-27 07:56:21 +04:00
|
|
|
|
|
2024-05-02 00:46:24 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateRefill(RefillBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-05-27 07:56:21 +04:00
|
|
|
|
_refill.Create(model);
|
2024-05-02 00:46:24 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-05-27 07:56:21 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка создания прививки");
|
2024-05-02 00:46:24 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-27 07:56:21 +04:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public bool UpdateRefill(RefillBindingModel model)
|
2024-05-02 00:46:24 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-05-27 07:56:21 +04:00
|
|
|
|
return _refill.Update(model);
|
2024-05-02 00:46:24 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-05-27 07:56:21 +04:00
|
|
|
|
_logger.LogError(ex, "Не удалось обновить привику");
|
2024-05-02 00:46:24 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-27 07:56:21 +04:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public bool DeleteRefill(RefillBindingModel model)
|
2024-05-02 00:46:24 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-05-27 07:56:21 +04:00
|
|
|
|
return _refill.Delete(model);
|
2024-05-02 00:46:24 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-05-27 07:56:21 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка удаления привики");
|
2024-05-02 00:46:24 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-27 07:56:21 +04:00
|
|
|
|
}
|