using Microsoft.Extensions.Logging; using ServiceStationContracts.BusinessLogic; 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(WorkClientBindingModel model) { CheckModel(model); if (!_storage.Add_Points(model)) { _logger.LogWarning("Add_Points operatin failed"); return false; } return true; } private void CheckModel(WorkClientBindingModel 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("Нет такой работы или такого клиента"); } } } }