using ClientsContracts.BindingModels; using ClientsContracts.BusinessLogicContracts; using ClientsContracts.StorageContracts; using ClientsContracts.ViewModels; namespace ClientBusinessLogic.BusinessLogics { public class StatusLogic : IStatusLogic { private readonly IStatusStorage _statusStorage; public StatusLogic(IStatusStorage statusStorage) { _statusStorage = statusStorage; } public void CreateOrUpdate(StatusBindingModel model) { var element = _statusStorage.GetElement( new StatusBindingModel { Name = model.Name }); if (element != null && element.Id != model.Id) { throw new Exception("Такой статус уже существует"); } if (model.Id.HasValue) { _statusStorage.Update(model); } else { _statusStorage.Insert(model); } } public void Delete(StatusBindingModel model) { var element = _statusStorage.GetElement(new StatusBindingModel { Id = model.Id }); if (element == null) { throw new Exception("Статус не найден"); } _statusStorage.Delete(model); } public List Read(StatusBindingModel model) { if (model == null) { return _statusStorage.GetFullList(); } if (model.Id.HasValue) { return new List { _statusStorage.GetElement(model) }; } return _statusStorage.GetFilteredList(model); } } }