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

94 lines
2.5 KiB
C#
Raw Normal View History

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 TermController : Controller
{
private readonly ILogger _logger;
private readonly ITermLogic _logic;
public TermController(ILogger<TermController> logger,
ITermLogic logic)
{
_logger = logger;
_logic = logic;
}
[HttpGet]
public List<TermViewModel>? GetTermList()
{
try
{
return _logic.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка сроков");
throw;
}
}
[HttpGet]
public TermViewModel? GetTerm(int TermId)
{
try
{
return _logic.ReadElement(new TermSearchModel
{
Id = TermId
});
}
catch (Exception ex)
{
_logger.LogError(
ex, "Ошибка получения срока по Id={Id}",
TermId);
throw;
}
}
[HttpPost]
public void CreateTerm(TermBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания срока");
throw;
}
}
[HttpPut]
public void UpdateTerm(TermBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления срока");
throw;
}
}
[HttpDelete]
public void DeleteTerm(TermBindingModel model)
{
try
{
_logic.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления срока");
throw;
}
}
}
}