using ComputerStoreContracts.BindingModels; using ComputerStoreContracts.BusinessLogicContracts; using ComputerStoreContracts.SearchModels; 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 IRequestComponentLogic _requestComponentLogic; private readonly IEmployeeReportLogic _employeeReportLogic; private readonly IRequestLogic _requestLogic; public MainController(ILogger logger, IComponentLogic componentLogic, IPCLogic pcLogic, IProductLogic productLogic, IEmployeeReportLogic employeeReportLogic, IRequestComponentLogic requestComponentLogic, IRequestLogic requestLogic) { _logger = logger; _componentLogic = componentLogic; _pcLogic = pcLogic; _productLogic = productLogic; _employeeReportLogic = employeeReportLogic; _requestComponentLogic = requestComponentLogic; _requestLogic = requestLogic; } [HttpGet] public List? GetComponentsList() { try { return _componentLogic.ReadList(null); } catch(Exception ex) { _logger.LogError(ex, "Receiving list of components error."); throw; } } [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; } } [HttpDelete("{id}")] public bool DeleteComponent(int id) { try { return _componentLogic.Delete(new ComponentBindingModel { ID = id }); } 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? GetProductsList() { try { return _productLogic.ReadList(null); } catch (Exception ex) { _logger.LogError(ex, "Receiving list of products error."); throw; } } [HttpDelete("{id}")] public bool DeleteProduct(int id) { try { return _productLogic.Delete(new ProductBindingModel { ID = id }); } 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? GetPCsList() { try { return _pcLogic.ReadList(null); } catch (Exception ex) { _logger.LogError(ex, "Receiving list of PCs error."); throw; } } [HttpDelete("{id}")] public bool DeletePC(int id) { try { return _pcLogic.Delete(new PCBindingModel { ID = id}); } 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; } } [HttpGet] public List? GetRequestComponentList(int? id) { try { return _requestComponentLogic.ReadList(new RequestSearchModel { ID = id}); } catch (Exception ex) { _logger.LogError(ex, "Receiving list of requestcomponent error."); throw; } } [HttpGet] public List? GetRequestList() { try { return _requestLogic.ReadList(null); } catch (Exception ex) { _logger.LogError(ex, "Receiving list of requestcomponent error."); throw; } } } }