using Microsoft.Extensions.Logging; using ServiceStationContracts.BusinessLogic; using ServiceStationContracts.HelperModels; using ServiceStationContracts.SearchModels; using ServiceStationContracts.StorageContracts; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ServiceStationBusinessLogic.BusinessLogic { public class WorkClientLogic : IWorkClientLogic { private readonly ILogger _logger; private readonly IWorkClientStorage _storage; private readonly IWorkStorage _workStorage; private readonly IClientStorage _clientStorage; public WorkClientLogic(ILogger logger, IWorkClientStorage storage, IWorkStorage workStorage, IClientStorage clientStorage) { _logger = logger; _storage = storage; _workStorage = workStorage; _clientStorage = clientStorage; } public bool Add_Points(WorkClientModel model) { CheckModel(model); if (!_storage.Add_Points(model)) { _logger.LogWarning("Add_Points operatin failed"); return false; } return true; } public List? ReadList(WorkClientSearchModel model) { _logger.LogInformation($"ReadList.client_id:{model.client_id}"); var list = _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(WorkClientModel model) { if (model.Point_count < 0) { throw new ArgumentNullException("Нельзя ставить отрицательное количество баллов"); } var work = _workStorage.GetElement(new ServiceStationContracts.SearchModels.WorkSearchModel { Id = model.Work_Id }); var client = _clientStorage.GetElement(new ServiceStationContracts.SearchModels.ClientSearchModel { Id = model.Client_Id }); if (work == null || client == null) { throw new ArgumentNullException("Нет такой работы или такого клиента"); } } } }