CourseWork_CompShop/ComputerShopProvider/ComputerShopRestApi/Controllers/OrderController.cs

95 lines
2.5 KiB
C#
Raw Normal View History

2023-05-19 18:26:38 +04:00
using ComputerShopContracts.BindingModels;
using ComputerShopContracts.BusinessLogicContracts;
using ComputerShopContracts.SearchModels;
using ComputerShopContracts.ViewModels;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
2023-12-02 01:39:39 +04:00
using System.Reflection;
2023-05-19 18:26:38 +04:00
namespace ComputerShopRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
2023-05-19 18:26:38 +04:00
public class OrderController : Controller
{
private readonly ILogger _logger;
private readonly IOrderLogic _order;
2023-05-19 18:26:38 +04:00
public OrderController(ILogger<MainController> logger, IOrderLogic order, ISupplyLogic supply)
2023-05-19 18:26:38 +04:00
{
_logger = logger;
_order = order;
2023-05-19 18:26:38 +04:00
}
[HttpGet]
public List<OrderViewModel>? GetOrderList(int clientId)
2023-05-19 18:26:38 +04:00
{
2023-05-19 18:26:38 +04:00
try
{
return _order.ReadList(new OrderSearchModel { ClientId = clientId });
2023-05-19 18:26:38 +04:00
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка заказов");
2023-05-19 18:26:38 +04:00
throw;
}
}
[HttpGet]
public List<OrderViewModel>? GetOrders(int clientId)
{
try
{
return _order.ReadList(new OrderSearchModel {});
2023-05-19 18:26:38 +04:00
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", clientId);
throw;
}
}
[HttpPost]
public void CreateOrder(OrderBindingModel model)
{
try
{
_order.CreateOrder(model);
2023-05-19 18:26:38 +04:00
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания заказа");
throw;
}
}
[HttpDelete]
public void DeleteOrder(OrderBindingModel model)
{
try
{
_order.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении заказа");
throw;
}
}
2023-12-02 01:39:39 +04:00
[HttpPost]
public void AddAssembly(Tuple<OrderSearchModel, AssemblySearchModel, int> model)
{
try
{
_order.AddAssembly(model.Item1, model.Item2, model.Item3);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка добавления компонента в сборку.");
throw;
}
}
}
2023-05-19 18:26:38 +04:00
}