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-05-20 08:34:33 +04:00
|
|
|
|
private readonly IEquipmentReceivingLogic _equipmentReceiving;
|
|
|
|
|
|
|
|
|
|
public SupplyController(ILogger<SupplyController> logger, ISupplyLogic supply, IOrderLogic order, IEquipmentReceivingLogic equipmentReceiving)
|
2023-05-20 01:31:46 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_supply = supply;
|
|
|
|
|
_order = order;
|
2023-05-20 08:34:33 +04:00
|
|
|
|
_equipmentReceiving = equipmentReceiving;
|
2023-05-20 01:31:46 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2023-05-20 08:34:33 +04:00
|
|
|
|
public List<EquipmentReceivingViewModel>? GetReceivingList()
|
2023-05-20 01:31:46 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-05-20 08:34:33 +04:00
|
|
|
|
return _equipmentReceiving.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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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 08:34:33 +04:00
|
|
|
|
public void CreateAssembly(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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|