2023-05-12 18:18:56 +04:00
|
|
|
|
using ComputerStoreContracts.BindingModels;
|
|
|
|
|
using ComputerStoreContracts.BusinessLogicContracts;
|
2023-05-13 22:45:29 +04:00
|
|
|
|
using ComputerStoreContracts.SearchModels;
|
2023-05-12 18:18:56 +04:00
|
|
|
|
using ComputerStoreContracts.ViewModels;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace ComputerStoreRestAPI.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class MainController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IComponentLogic _componentLogic;
|
|
|
|
|
private readonly IPCLogic _pcLogic;
|
|
|
|
|
private readonly IProductLogic _productLogic;
|
2023-05-17 17:57:25 +04:00
|
|
|
|
private readonly IRequestComponentLogic _requestComponentLogic;
|
2023-05-12 18:18:56 +04:00
|
|
|
|
private readonly IEmployeeReportLogic _employeeReportLogic;
|
2023-05-17 17:57:25 +04:00
|
|
|
|
private readonly IRequestLogic _requestLogic;
|
2023-05-12 18:18:56 +04:00
|
|
|
|
|
2023-05-19 16:11:31 +04:00
|
|
|
|
private readonly IOrderLogic _orderLogic;
|
|
|
|
|
private readonly IConsignmentLogic _consignmentLogic;
|
|
|
|
|
private readonly IReportOrderLogic _reportOrderLogic;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MainController(
|
|
|
|
|
ILogger<MainController> logger,
|
|
|
|
|
IComponentLogic componentLogic,
|
|
|
|
|
IPCLogic pcLogic,
|
|
|
|
|
IProductLogic productLogic,
|
|
|
|
|
IEmployeeReportLogic employeeReportLogic,
|
|
|
|
|
IRequestComponentLogic requestComponentLogic,
|
|
|
|
|
IRequestLogic requestLogic,
|
|
|
|
|
IOrderLogic orderLogic,
|
|
|
|
|
IConsignmentLogic consignmentLogic,
|
|
|
|
|
IReportOrderLogic reportOrderLogic)
|
2023-05-12 18:18:56 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_componentLogic = componentLogic;
|
|
|
|
|
_pcLogic = pcLogic;
|
|
|
|
|
_productLogic = productLogic;
|
|
|
|
|
_employeeReportLogic = employeeReportLogic;
|
2023-05-17 17:57:25 +04:00
|
|
|
|
_requestComponentLogic = requestComponentLogic;
|
|
|
|
|
_requestLogic = requestLogic;
|
2023-05-19 16:11:31 +04:00
|
|
|
|
_orderLogic = orderLogic;
|
|
|
|
|
_consignmentLogic = consignmentLogic;
|
|
|
|
|
_reportOrderLogic = reportOrderLogic;
|
2023-05-12 18:18:56 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<ComponentViewModel>? GetComponentsList()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _componentLogic.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Receiving list of components error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-13 22:45:29 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public ComponentViewModel? GetComponent(int id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _componentLogic.ReadElement(new ComponentSearchModel { ID = id } );
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Receiving list of components error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-13 21:17:24 +04:00
|
|
|
|
[HttpDelete("{id}")]
|
|
|
|
|
public bool DeleteComponent(int id)
|
2023-05-12 18:18:56 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-05-13 21:17:24 +04:00
|
|
|
|
return _componentLogic.Delete(new ComponentBindingModel { ID = id });
|
2023-05-12 18:18:56 +04:00
|
|
|
|
}
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Removing component error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPatch]
|
|
|
|
|
public bool UpdateComponent(ComponentBindingModel component)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _componentLogic.Update(component);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Updating component error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public bool InsertComponent(ComponentBindingModel component)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _componentLogic.Create(component);
|
|
|
|
|
}
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Inserting component error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<ProductViewModel>? GetProductsList()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _productLogic.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Receiving list of products error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-13 22:16:58 +04:00
|
|
|
|
[HttpDelete("{id}")]
|
|
|
|
|
public bool DeleteProduct(int id)
|
2023-05-12 18:18:56 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-05-13 22:16:58 +04:00
|
|
|
|
return _productLogic.Delete(new ProductBindingModel { ID = id });
|
2023-05-12 18:18:56 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Removing product error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPatch]
|
|
|
|
|
public bool UpdateProduct(ProductBindingModel product)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _productLogic.Update(product);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Updating product error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public bool InsertProduct(ProductBindingModel product)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _productLogic.Create(product);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Inserting product error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<PCViewModel>? GetPCsList()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _pcLogic.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Receiving list of PCs error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-13 22:16:58 +04:00
|
|
|
|
[HttpDelete("{id}")]
|
|
|
|
|
public bool DeletePC(int id)
|
2023-05-12 18:18:56 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-05-13 22:16:58 +04:00
|
|
|
|
return _pcLogic.Delete(new PCBindingModel { ID = id});
|
2023-05-12 18:18:56 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Removing PC error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPatch]
|
|
|
|
|
public bool UpdateProduct(PCBindingModel pc)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _pcLogic.Update(pc);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Updating PC error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public bool InsertProduct(PCBindingModel pc)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _pcLogic.Create(pc);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Inserting PC error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-17 17:57:25 +04:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<RequestComponentViewModel>? GetRequestComponentList(int? id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _requestComponentLogic.ReadList(new RequestSearchModel { ID = id});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Receiving list of requestcomponent error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 16:11:31 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Request
|
|
|
|
|
[HttpGet]
|
2023-05-17 17:57:25 +04:00
|
|
|
|
public List<RequestViewModel>? GetRequestList()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _requestLogic.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Receiving list of requestcomponent error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-19 16:11:31 +04:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public RequestViewModel? GetRequest(int id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _requestLogic.ReadElement(new RequestSearchModel { ID = id });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Receiving request error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpDelete("{id}")]
|
|
|
|
|
public bool DeleteRequest(int id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _requestLogic.Delete(new RequestBindingModel { ID = id });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Removing request error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPatch]
|
|
|
|
|
public bool UpdateRequest(RequestBindingModel request)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _requestLogic.Update(request);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Updating request error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public bool InsertRequest(RequestBindingModel request)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _requestLogic.Create(request);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Inserting request error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Order
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<OrderViewModel>? GetOrdersList()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _orderLogic.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Receiving list of orders error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPatch]
|
|
|
|
|
public bool UpdateOrderInProcess(OrderBindingModel order)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _orderLogic.TakeOrderInProcess(order);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Updating order in process error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPatch]
|
|
|
|
|
public bool UpdateOrderReady(OrderBindingModel order)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _orderLogic.TakeOrderReady(order);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Updating order ready error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPatch]
|
|
|
|
|
public bool UpdateOrderGiven(OrderBindingModel order)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _orderLogic.TakeOrderGiven(order);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Updating order given error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public bool InsertOrder(OrderBindingModel order)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _orderLogic.CreateOrder(order);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Inserting order error.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
2023-05-12 18:18:56 +04:00
|
|
|
|
}
|