67 lines
1.8 KiB
C#
67 lines
1.8 KiB
C#
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<HistoryViewModel> Read(HistoryBindingModel model)
|
|
{
|
|
if(model == null)
|
|
{
|
|
return _historyStorage.GetFullList();
|
|
}
|
|
if (model.Id.HasValue) {
|
|
return new List<HistoryViewModel>
|
|
{
|
|
_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);
|
|
}
|
|
}
|
|
}
|