Exemplo n.º 1
0
 static private void validateCustomBusinessRulesOrderProducts(OrderDto orderDto, Validator <OrderDto, Order> validator)
 {
     if (orderDto.ProductItems == null ||
         orderDto.ProductItems.Count <= 0)
     {
         var validatorError = new List <ValidatorError>();
         validatorError.Add(new ValidatorError
         {
             Code   = "NoProducts",
             Detail = new ValidatorErrorDetail {
                 Messages = new List <string> {
                     "Non è stato selezionano nessun prodotto"
                 }
             },
             GeneratorClass = "OrderFactory",
             Type           = ValidatorType.Business
         });
         validator.AddCustomBrokenRule(validatorError);
     }
 }
Exemplo n.º 2
0
        static private async Task createOptionItemAsync(OrderItemDto orderItemDto, Validator <OrderItemDto, OrderItem> validatorItem,
                                                        IEnumerable <IRuleSpecification <OrderItemOptionDto> > optionItemRules)
        {
            if (orderItemDto.OptionItems == null)
            {
                return;
            }

            foreach (var item in orderItemDto.OptionItems)
            {
                var validatorOption = await OrderItemOption.CreateOptionItemAsync(item, optionItemRules);

                if (!validatorOption.IsValid)
                {
                    validatorOption.BrokenRules?.ForEach(i => validatorItem.AddCustomBrokenRule(i));
                }
                else
                {
                    validatorItem.ValidatedObject._itemOptions.Add(validatorOption.ValidatedObject);
                }
            }
        }
Exemplo n.º 3
0
        static private async Task createOrderItemAsync(OrderDto orderDto, Validator <OrderDto, Order> orderValidator,
                                                       IEnumerable <IRuleSpecification <OrderItemDto> > orderItemRules,
                                                       IEnumerable <IRuleSpecification <OrderItemOptionDto> > optionItemRules)
        {
            if (orderDto.ProductItems == null)
            {
                return;
            }

            foreach (var item in orderDto.ProductItems)
            {
                var validatorSingleItem = await OrderItem.CreateOrderItemAsync(item, orderItemRules, optionItemRules);

                if (!validatorSingleItem.IsValid)
                {
                    validatorSingleItem.BrokenRules?.ForEach(i => orderValidator.AddCustomBrokenRule(i));
                }
                else
                {
                    orderValidator.ValidatedObject._orderItems.Add(validatorSingleItem.ValidatedObject);
                }
            }
        }