using ComputerShopContracts.BindingModels; using ComputerShopContracts.BusinessLogicContracts; using ComputerShopContracts.SearchModels; using ComputerShopContracts.StorageContracts; using ComputerShopContracts.ViewModels; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace ComputerShopBusinessLogic.BusinessLogics { public class RequestLogic : IRequestLogic { private readonly ILogger _logger; private readonly IRequestStorage _requestStorage; public RequestLogic(ILogger logger, IRequestStorage requestStorage) { _logger = logger; _requestStorage = requestStorage; } public List? ReadList(RequestSearchModel? model) { var list = (model == null ) ? _requestStorage.GetFullList() : _requestStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("Null list"); return null; } return list; } public RequestViewModel? ReadElement(RequestSearchModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var element = _requestStorage.GetElement(model); if (element == null) { _logger.LogWarning("ReadElement request not found"); return null; } return element; } public bool Create(RequestBindingModel model) { CheckModel(model); if (_requestStorage.Insert(model) == null) { _logger.LogWarning("Insert failed"); return false; } return true; } public bool Update(RequestBindingModel model) { CheckModel(model); if (_requestStorage.Update(model) == null) { _logger.LogWarning("Update failed"); return false; } return true; } public bool ConnectRequestAssembly(int requestId, int assemblyId) { _logger.LogInformation("Connect Assembly {rId} with request {aId}", requestId, assemblyId); return _requestStorage.ConnectRequestAssembly(requestId, assemblyId); } public bool Delete(RequestBindingModel model) { CheckModel(model, false); _logger.LogInformation("Delete. Id:{Id}", model.Id); if (_requestStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); return false; } return true; } } }