using Microsoft.Extensions.Logging; using ServiceStationContracts.BindingModels; using ServiceStationContracts.BusinessLogicContracts; using ServiceStationContracts.SearchModels; using ServiceStationContracts.ViewModels; using ServiceStationsContracts.StorageContracts; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ServiceSourceBusinessLogic.BusinessLogic { public class ReportLogic : IReportLogic { private readonly ILogger _logger; private readonly ITaskStorage _storage; public ReportLogic(ILogger logger, ITaskStorage storage) { _logger = logger; _storage = storage; } public bool Create(ReportBindingModel model) { CheckModel(model); if (_storage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); return false; } return true; } public bool Delete(ReportBindingModel model) { CheckModel(model, false); _logger.LogInformation($"Delete. Id:{model.Id}"); if (_storage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); return false; } return true; } public bool Update(ReportBindingModel model) { CheckModel(model); if (_storage.Update(model) == null) { _logger.LogWarning("Update operation failed"); return false; } return true; } public List? ReadList(TaskSearchModel model) { _logger.LogInformation($"ReadList. Id:{model?.Id}"); var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); return null; } _logger.LogInformation($"ReadList. Count:{list.Count}"); return list; } private void CheckModel(ReportBindingModel model, bool withParams = true) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (!withParams) { return; } if (string.IsNullOrEmpty((model.Id).ToString())) { throw new ArgumentNullException("Нет Id отчета", nameof(model.Id)); } if (model.Count == 0) { throw new ArgumentNullException("Нет отчетов", nameof(model.Id)); } _logger.LogInformation($"Report. Id:{model.Id}.Count:{model.Count}"); } } }