2023-04-07 18:59:41 +04:00
|
|
|
|
using ComputerShopContracts.BindingModels;
|
|
|
|
|
using ComputerShopContracts.BusinessLogicContracts;
|
|
|
|
|
using ComputerShopContracts.SearchModels;
|
2023-05-20 07:41:13 +04:00
|
|
|
|
using ComputerShopContracts.StorageContracts;
|
2023-04-07 18:59:41 +04:00
|
|
|
|
using ComputerShopContracts.ViewModels;
|
2023-05-20 07:41:13 +04:00
|
|
|
|
using DocumentFormat.OpenXml.Presentation;
|
2023-04-07 18:59:41 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace ComputerShopRestApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class MainController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IPurchaseLogic _purchase;
|
2023-05-20 07:41:13 +04:00
|
|
|
|
private readonly IPurchaseStorage _purchaseSTR;
|
2023-04-07 18:59:41 +04:00
|
|
|
|
private readonly IComponentLogic _component;
|
2023-05-20 07:41:13 +04:00
|
|
|
|
public MainController(ILogger<MainController> logger, IPurchaseLogic purchase, IComponentLogic component, IPurchaseStorage purchaseStorage)
|
2023-04-07 18:59:41 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_purchase = purchase;
|
|
|
|
|
_component = component;
|
2023-05-20 07:41:13 +04:00
|
|
|
|
_purchaseSTR = purchaseStorage;
|
2023-04-07 18:59:41 +04:00
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<ComponentViewModel>? GetComponentList()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _component.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка компонентов");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public ComponentViewModel? GetComponent(int componentId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _component.ReadElement(new ComponentSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = componentId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения компонента по id={Id}", componentId);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<PurchaseViewModel>? GetPurchases(int clientId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _purchase.ReadList(new PurchaseSearchModel
|
|
|
|
|
{
|
|
|
|
|
ClientId = clientId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка закупок клиента id ={ Id}", clientId);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreatePurchase(PurchaseBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_purchase.CreatePurchase(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания закупки");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-20 07:41:13 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void SetInWork(int id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var puchase = _purchaseSTR.GetElement(new() { Id = id });
|
|
|
|
|
_purchase.TakePurchaseInWork(new()
|
|
|
|
|
{
|
|
|
|
|
Id = id,
|
|
|
|
|
ComponentId = puchase.ComponentId,
|
|
|
|
|
Count = puchase.Count,
|
|
|
|
|
Sum = puchase.Sum,
|
|
|
|
|
Status = puchase.Status
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка изменения закупки");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void SetReady(int id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var puchase = _purchaseSTR.GetElement(new() { Id = id });
|
|
|
|
|
_purchase.FinishPurchase(new()
|
|
|
|
|
{
|
|
|
|
|
Id = id,
|
|
|
|
|
ComponentId = puchase.ComponentId,
|
|
|
|
|
Count = puchase.Count,
|
|
|
|
|
Sum = puchase.Sum,
|
|
|
|
|
Status = puchase.Status
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка изменения закупки");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void SetDone(int id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var puchase = _purchaseSTR.GetElement(new() { Id = id });
|
|
|
|
|
_purchase.DeliveryPurchase(new()
|
|
|
|
|
{
|
|
|
|
|
Id = id,
|
|
|
|
|
ComponentId = puchase.ComponentId,
|
|
|
|
|
Count = puchase.Count,
|
|
|
|
|
Sum = puchase.Sum,
|
|
|
|
|
Status = puchase.Status
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка изменения закупки");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-07 18:59:41 +04:00
|
|
|
|
}
|
|
|
|
|
}
|