public OrderEditService(AbstractOmsDbContext dbContext, IOrderValidator orderValidator, IOrderItemCollectionValidator orderItemsValidator) { _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); _orderValidator = orderValidator ?? throw new ArgumentNullException(nameof(orderValidator)); _orderItemsValidator = orderItemsValidator ?? throw new ArgumentNullException(nameof(orderItemsValidator)); }
public OrderService(AbstractOmsDbContext dbContext, IOrderValidator orderValidator, IOrderItemCollectionValidator orderItemsValidator, IEmailTemplate emailTemplate, IEmail email) { _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); _orderValidator = orderValidator ?? throw new ArgumentNullException(nameof(orderValidator)); _orderItemsValidator = orderItemsValidator ?? throw new ArgumentNullException(nameof(orderItemsValidator)); _emailTemplate = emailTemplate ?? throw new ArgumentNullException(nameof(emailTemplate)); _email = email ?? throw new ArgumentNullException(nameof(email)); }
public void ValidateItemsAndThrow(IEnumerable <OrderItem> orderItems, AbstractOmsDbContext abstractOmsDbContext) { RuleForEach(items => items) .ChildRules(item => { item.RuleFor(x => x.Quantity).GreaterThan(0); item.RuleFor(x => x.ProductId).GreaterThan(0); item.RuleFor(x => x).Custom((x, context) => { ProductEntity productEntity = abstractOmsDbContext.Products.SingleOrDefault(product => product.Id == x.ProductId); if (productEntity == null) { context.AddFailure($"Specified product number {x.ProductId} does not exist."); } else if (productEntity.AvailableQuantity < x.Quantity) { context.AddFailure($"Product {productEntity.Name} is not in stock"); } }); }); this.ValidateAndThrow(orderItems); }
public OrderQueryService(AbstractOmsDbContext dbContext) { _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); }