using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using VetClinicBusinessLogic.BindingModels; using VetClinicBusinessLogic.Interfaces; using VetClinicBusinessLogic.ViewModels; namespace VetClinicBusinessLogic.BusinessLogic { public class ServiceLogic { private readonly IServiceStorage _ServicesStorage; public ServiceLogic(IServiceStorage ServicesStorage) { _ServicesStorage = ServicesStorage; } public List Read(ServiceBindingModel model) { if (model == null) { return _ServicesStorage.GetFullList(); } if (model.Id.HasValue) { return new List { _ServicesStorage.GetElement(model) }; } return _ServicesStorage.GetFilteredList(model); } public void CreateOrUpdate(ServiceBindingModel model) { if (model.Id.HasValue) { _ServicesStorage.Update(model); } else { _ServicesStorage.Insert(model); } } public void Delete(ServiceBindingModel model) { var element = _ServicesStorage.GetElement(new ServiceBindingModel { Id = model.Id }); if (element == null) { throw new Exception("Услуга не найдена"); } _ServicesStorage.Delete(model); } } }