CourseWork_CompShop/ComputerShopProvider/ComputerShopRestApi/Controllers/SupplyController.cs

129 lines
3.6 KiB
C#
Raw Normal View History

using ComputerShopContracts.BindingModels;
using ComputerShopContracts.BusinessLogicContracts;
using ComputerShopContracts.SearchModels;
using ComputerShopContracts.ViewModels;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace ComputerShopRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class SupplyController : Controller
{
private readonly ILogger _logger;
private readonly ISupplyLogic _supply;
private readonly IOrderLogic _order;
2023-12-01 19:59:06 +04:00
private readonly IComponentLogic _component;
2023-05-20 08:34:33 +04:00
2023-12-01 19:59:06 +04:00
public SupplyController(ILogger<SupplyController> logger, ISupplyLogic supply, IOrderLogic order, IComponentLogic component)
{
_logger = logger;
_supply = supply;
_order = order;
2023-12-01 19:59:06 +04:00
_component = component;
}
[HttpGet]
2023-12-01 19:59:06 +04:00
public List<ComponentViewModel>? GetReceivingList(int clientId)
{
2023-05-20 09:23:37 +04:00
try
{
2023-12-01 19:59:06 +04:00
return _component.ReadList(new ComponentSearchModel
2023-05-20 09:23:37 +04:00
{
ClientId = clientId
});
}
catch (Exception ex)
{
2023-12-01 19:59:06 +04:00
_logger.LogError(ex, "Ошибка получения списка комплектующих клиента id ={ Id}", clientId);
throw;
}
}
[HttpGet]
2023-05-20 08:34:33 +04:00
public List<SupplyViewModel>? GetSupplyList(int componentid)
{
try
{
2023-05-20 08:34:33 +04:00
return _supply.ReadList(new SupplySearchModel { ComponentId = componentid });
}
catch (Exception ex)
{
2023-05-20 08:34:33 +04:00
_logger.LogError(ex, "Ошибка получения списка сборок");
throw;
}
}
2023-12-01 19:59:06 +04:00
[HttpGet]
2023-05-20 08:34:33 +04:00
public List<OrderViewModel>? GetOrderList()
{
try
{
2023-05-20 08:34:33 +04:00
return _order.ReadList(null);
}
catch (Exception ex)
{
2023-05-20 08:34:33 +04:00
_logger.LogError(ex, "Ошибка получения списка заказов");
throw;
}
}
[HttpPost]
2023-05-20 09:23:37 +04:00
public void CreateSupply(SupplyBindingModel model)
{
try
{
2023-05-20 08:34:33 +04:00
_supply.Create(model);
}
catch (Exception ex)
{
2023-05-20 08:34:33 +04:00
_logger.LogError(ex, "Ошибка создания поставки");
throw;
}
}
[HttpPost]
2023-05-20 08:34:33 +04:00
public void DeleteSupply(SupplyBindingModel model)
{
try
{
2023-05-20 08:34:33 +04:00
_supply.Delete(model);
}
catch (Exception ex)
{
2023-05-20 08:34:33 +04:00
_logger.LogError(ex, "Ошибка удаления поставки");
throw;
}
}
[HttpPost]
2023-05-20 08:34:33 +04:00
public void AddOrderToSupply(Tuple<SupplySearchModel, OrderSearchModel> model)
{
try
{
2023-05-20 08:34:33 +04:00
_supply.AddOrder(model.Item1, model.Item2);
}
catch (Exception ex)
{
2023-05-20 08:34:33 +04:00
_logger.LogError(ex, "Ошибка.");
throw;
}
}
[HttpPost]
2023-05-20 08:34:33 +04:00
public void EditOrder(OrderBindingModel model)
{
try
{
2023-05-20 08:34:33 +04:00
_order.Update(model);
}
catch (Exception ex)
{
2023-05-20 08:34:33 +04:00
_logger.LogError(ex, "Ошибка удаления заказа");
throw;
}
}
}
}