95 lines
2.7 KiB
C#
95 lines
2.7 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 ProgramController : Controller
|
|||
|
{
|
|||
|
private readonly ILogger _logger;
|
|||
|
private readonly IProgramLogic _logic;
|
|||
|
public ProgramController(ILogger<ProgramController> logger,
|
|||
|
IProgramLogic logic)
|
|||
|
{
|
|||
|
_logger = logger;
|
|||
|
_logic = logic;
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public List<ProgramViewModel>? GetProgramList()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
return _logic.ReadList(null);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(
|
|||
|
ex, "Ошибка получения списка кредитных программ");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
[HttpGet]
|
|||
|
public ProgramViewModel? GetProgram(int ProgramId)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
return _logic.ReadElement(new ProgramSearchModel
|
|||
|
{
|
|||
|
Id = ProgramId
|
|||
|
});
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(
|
|||
|
ex, "Ошибка получения кредитной программы по Id={Id}",
|
|||
|
ProgramId);
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
[HttpPost]
|
|||
|
public void CreateProgram(ProgramBindingModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
_logic.Create(model);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка создания кредитной программы");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
[HttpPut]
|
|||
|
public void UpdateProgram(ProgramBindingModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
_logic.Update(model);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка обновления кредитной программы");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
[HttpDelete]
|
|||
|
public void DeleteProgram(ProgramBindingModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
_logic.Delete(model);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка удаления кредитной программы");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|