76 lines
2.3 KiB
C#
76 lines
2.3 KiB
C#
using SecuritySystemContracts.BindingModels;
|
|
using SecuritySystemContracts.BusinessLogicsContracts;
|
|
using SecuritySystemContracts.SearchModels;
|
|
using SecuritySystemContracts.ViewModels;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
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, "Ошибка получения списка продуктов");
|
|
throw;
|
|
}
|
|
}
|
|
[HttpGet]
|
|
public SecureViewModel? GetSecure(int SecureId)
|
|
{
|
|
try
|
|
{
|
|
return _Secure.ReadElement(new SecureSearchModel { Id = SecureId });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения продукта по 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;
|
|
}
|
|
}
|
|
}
|
|
}
|