94 lines
2.5 KiB
C#
94 lines
2.5 KiB
C#
using BankContracts.BindingModels;
|
|
using BankContracts.BusinessLogicsContracts;
|
|
using BankContracts.SearchModels;
|
|
using BankContracts.ViewModels;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace BankRestApi.Controllers
|
|
{
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class DealController : Controller
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IDealLogic _deal;
|
|
|
|
public DealController(ILogger<DealController> logger, IDealLogic deal)
|
|
{
|
|
_logger = logger;
|
|
_deal = deal;
|
|
}
|
|
[HttpGet]
|
|
public List<DealViewModel>? GetDealsList()
|
|
{
|
|
try
|
|
{
|
|
return _deal.ReadList(null);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения списка сделок");
|
|
throw;
|
|
}
|
|
}
|
|
[HttpGet]
|
|
public List<DealViewModel>? GetDeals(int operatorId)
|
|
{
|
|
try
|
|
{
|
|
return _deal.ReadList(new DealSearchModel { OperatorId = operatorId});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения списка сделок оператора id={Id}", operatorId);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void CreateDeal(DealBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_deal.Create(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка создания сделки");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPatch]
|
|
public void UpdateDeal(DealBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_deal.Update(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка обновления сделки");
|
|
throw;
|
|
}
|
|
}
|
|
[HttpDelete]
|
|
public void DeleteDeal(int dealId)
|
|
{
|
|
try
|
|
{
|
|
DealBindingModel model = new DealBindingModel
|
|
{
|
|
Id = dealId,
|
|
};
|
|
_deal.Delete(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка удаления сделки");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|