82 lines
2.4 KiB
C#
82 lines
2.4 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using SecuritySystemContracts.BindingModels;
|
|
using SecuritySystemContracts.BusinessLogicsContracts;
|
|
using SecuritySystemContracts.SearchModels;
|
|
using SecuritySystemContracts.ViewModels;
|
|
|
|
namespace SecuritySystemRestApi.Controllers
|
|
{
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class MainController : Controller
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IOrderLogic _order;
|
|
private readonly ISecureLogic _secure;
|
|
public MainController(ILogger<MainController> logger, IOrderLogic order, ISecureLogic secure)
|
|
{
|
|
_logger = logger;
|
|
_order = order;
|
|
_secure = secure;
|
|
}
|
|
[HttpGet]
|
|
public List<SecureViewModel>? GetSecureList()
|
|
{
|
|
try
|
|
{
|
|
return _secure.ReadList(null);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения списка secures");
|
|
throw;
|
|
}
|
|
}
|
|
[HttpGet]
|
|
public SecureViewModel? GetSecure(int secureId)
|
|
{
|
|
try
|
|
{
|
|
return _secure.ReadElement(new SecureSearchModel
|
|
{
|
|
Id = secureId
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения secure по id={Id}", secureId);
|
|
throw;
|
|
}
|
|
}
|
|
[HttpGet]
|
|
public List<OrderViewModel>? GetOrders(int clientId)
|
|
{
|
|
try
|
|
{
|
|
return _order.ReadList(new OrderSearchModel
|
|
{
|
|
ClientId = clientId
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения списка заказов клиента id = {Id}", clientId);
|
|
throw;
|
|
}
|
|
}
|
|
[HttpPost]
|
|
public void CreateOrder(OrderBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_order.CreateOrder(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка создания заказа");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|