using BookContract.BindingModels; using BookContract.BusinessLogicContracts; using BookContract.StorageContracts; using BookContract.ViewModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BookBusinessLogic.BusinessLogic { public class HistoryLogic : IHistoryLogic { private readonly IHistoryStorage _historyStorage; public HistoryLogic(IHistoryStorage historyStorage) { _historyStorage = historyStorage; } public List Read(HistoryBindingModel model) { if(model == null) { return _historyStorage.GetFullList(); } if (model.Id.HasValue) { return new List { _historyStorage.GetElement(model) }; } return _historyStorage.GetHistoryByBookId(model.BookId); } public void CreateOrUpdate(HistoryBindingModel model) { var element = _historyStorage.GetElement( new HistoryBindingModel { Id = model.Id, }); if (element != null && element.Id != model.Id) { throw new Exception("Такая связь уже существует"); } _historyStorage.Insert(model); } public void Delete(HistoryBindingModel model) { var element = _historyStorage.GetElement(new HistoryBindingModel { Id = model.Id }); if (element == null) { throw new Exception("Навык не найден"); } _historyStorage.Delete(model); } } }