示例#1
0
        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));
        }
示例#2
0
        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));
        }
示例#3
0
 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);
 }
示例#4
0
 public OrderQueryService(AbstractOmsDbContext dbContext)
 {
     _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
 }