using BeautySaloonContracts.BindingModels; using BeautySaloonContracts.BusinessLogicsContracts; using BeautySaloonContracts.SearchModels; using BeautySaloonContracts.StoragesContracts; using BeautySaloonContracts.ViewModels; namespace BeautySaloonBusinessLogic { public class OrderLogic : IOrderLogic { private readonly IOrderStorage _orderStorage; public OrderLogic(IOrderStorage orderStorage) { _orderStorage = orderStorage; } public bool CreateOrder(OrderBindingModel model) { CheckModel(model); if (_orderStorage.Insert(model) == null) { return false; } return true; } public OrderViewModel? ReadElement(OrderSearchModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var element = _orderStorage.GetElement(model); if (element == null) { return null; } return element; } public List? ReadList(OrderSearchModel? model) { var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); if (list == null) { return null; } return list; } public bool Update(OrderBindingModel model) { CheckModel(model); if (_orderStorage.Update(model) == null) { return false; } return true; } private void CheckModel(OrderBindingModel model, bool withParams = true) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (!withParams) { return; } if (model.Sum <= 0) { throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); } if (model.ClientId <= 0) { throw new ArgumentNullException("Некорректный идентификатор клиента", nameof(model.ClientId)); } if (model.EmployeeId <= 0) { throw new ArgumentNullException("Некорректный идентификатор сотрудника", nameof(model.ClientId)); } } } }