Пример #1
0
        public override string ToString()
        {
            var header   = "List of items in basket:\n";
            var itemsMsg = Items.Aggregate(header,
                                           (x, y) => $"{x}{y.Product.Name}: {y.Num}, price: {y.GetPrice()} ({y.Product.Price} per unit)\n");
            var msg   = Discounts.Aggregate("", (x, y) => $"{x}{y.GetDescription()}\n");
            var total = $"Total amount: {Total}\n";

            return(Discounts.Any() ? $"{itemsMsg}\n{msg}\n{total}" : total);
        }
Пример #2
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var nullProduct = Products.Any(x => x == null);

            if (nullProduct)
            {
                yield return(new ValidationResult("No products in the order"));
            }
            var emptyProductId = Products.Any(x => x.Id == Guid.Empty);

            if (emptyProductId)
            {
                yield return(new ValidationResult("Product ID is empty"));
            }
            var invalidProductCounter = Products.Any(x => x.Count <= 0);

            if (invalidProductCounter)
            {
                yield return(new ValidationResult("Invalid product counter"));
            }
            var nullDiscount = Discounts.Any(x => x == null);

            if (!nullDiscount)
            {
                var emptyDiscountId = Discounts.Any(x => x.Id == Guid.Empty);
                if (emptyDiscountId)
                {
                    yield return(new ValidationResult("Discount ID is empty"));
                }
                var invalidDiscountCounter = Discounts.Any(x => x.Count <= 0);
                if (invalidDiscountCounter)
                {
                    yield return(new ValidationResult("Invalid discount counter"));
                }
            }
        }