196 lines
5.1 KiB
C#
196 lines
5.1 KiB
C#
|
using ComputerStoreContracts.BindingModels;
|
|||
|
using ComputerStoreContracts.BusinessLogicContracts;
|
|||
|
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;
|
|||
|
private readonly IEmployeeReportLogic _employeeReportLogic;
|
|||
|
|
|||
|
public MainController(ILogger<MainController> logger, IComponentLogic componentLogic, IPCLogic pcLogic, IProductLogic productLogic, IEmployeeReportLogic employeeReportLogic)
|
|||
|
{
|
|||
|
_logger = logger;
|
|||
|
_componentLogic = componentLogic;
|
|||
|
_pcLogic = pcLogic;
|
|||
|
_productLogic = productLogic;
|
|||
|
_employeeReportLogic = employeeReportLogic;
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public List<ComponentViewModel>? GetComponentsList()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
return _componentLogic.ReadList(null);
|
|||
|
}
|
|||
|
catch(Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Receiving list of components error.");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpDelete]
|
|||
|
public bool DeleteComponent(ComponentBindingModel component)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
return _componentLogic.Delete(component);
|
|||
|
}
|
|||
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpDelete]
|
|||
|
public bool DeleteProduct(ProductBindingModel product)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
return _productLogic.Delete(product);
|
|||
|
}
|
|||
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpDelete]
|
|||
|
public bool DeletePC(PCBindingModel pc)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
return _pcLogic.Delete(pc);
|
|||
|
}
|
|||
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|