2023-05-20 01:31:46 +04:00
|
|
|
|
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)
|
2023-05-20 01:31:46 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_supply = supply;
|
|
|
|
|
_order = order;
|
2023-12-01 19:59:06 +04:00
|
|
|
|
_component = component;
|
2023-05-20 01:31:46 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2023-12-01 19:59:06 +04:00
|
|
|
|
public List<ComponentViewModel>? GetReceivingList(int clientId)
|
2023-05-20 01:31:46 +04:00
|
|
|
|
{
|
2023-05-20 09:23:37 +04:00
|
|
|
|
|
2023-05-20 01:31:46 +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
|
|
|
|
|
});
|
2023-05-20 01:31:46 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-12-01 19:59:06 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка комплектующих клиента id ={ Id}", clientId);
|
2023-05-20 01:31:46 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2023-05-20 08:34:33 +04:00
|
|
|
|
public List<SupplyViewModel>? GetSupplyList(int componentid)
|
2023-05-20 01:31:46 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-05-20 08:34:33 +04:00
|
|
|
|
return _supply.ReadList(new SupplySearchModel { ComponentId = componentid });
|
2023-05-20 01:31:46 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-05-20 08:34:33 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка сборок");
|
2023-05-20 01:31:46 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-01 19:59:06 +04:00
|
|
|
|
|
2023-05-20 01:31:46 +04:00
|
|
|
|
[HttpGet]
|
2023-05-20 08:34:33 +04:00
|
|
|
|
public List<OrderViewModel>? GetOrderList()
|
2023-05-20 01:31:46 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-05-20 08:34:33 +04:00
|
|
|
|
return _order.ReadList(null);
|
2023-05-20 01:31:46 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-05-20 08:34:33 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка заказов");
|
2023-05-20 01:31:46 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
2023-05-20 09:23:37 +04:00
|
|
|
|
public void CreateSupply(SupplyBindingModel model)
|
2023-05-20 01:31:46 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-05-20 08:34:33 +04:00
|
|
|
|
_supply.Create(model);
|
2023-05-20 01:31:46 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-05-20 08:34:33 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка создания поставки");
|
2023-05-20 01:31:46 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
2023-05-20 08:34:33 +04:00
|
|
|
|
public void DeleteSupply(SupplyBindingModel model)
|
2023-05-20 01:31:46 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-05-20 08:34:33 +04:00
|
|
|
|
_supply.Delete(model);
|
2023-05-20 01:31:46 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-05-20 08:34:33 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка удаления поставки");
|
2023-05-20 01:31:46 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2023-05-20 08:34:33 +04:00
|
|
|
|
public void AddOrderToSupply(Tuple<SupplySearchModel, OrderSearchModel> model)
|
2023-05-20 01:31:46 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-05-20 08:34:33 +04:00
|
|
|
|
_supply.AddOrder(model.Item1, model.Item2);
|
2023-05-20 01:31:46 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-05-20 08:34:33 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка.");
|
2023-05-20 01:31:46 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2023-05-20 08:34:33 +04:00
|
|
|
|
public void EditOrder(OrderBindingModel model)
|
2023-05-20 01:31:46 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-05-20 08:34:33 +04:00
|
|
|
|
_order.Update(model);
|
2023-05-20 01:31:46 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-05-20 08:34:33 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка удаления заказа");
|
2023-05-20 01:31:46 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|