Пример #1
0
        public void Validate()
        {
            if (string.IsNullOrWhiteSpace(OrderNumber))
            {
                throw new ValidationErrorException(nameof(OrderNumber));
            }
            if (TotalValue < 0)
            {
                throw new ValidationErrorException(nameof(TotalValue));
            }
            if (Customer == null)
            {
                throw new ValidationErrorException(nameof(Customer));
            }
            Customer.Validate();

            if (ShippingAddress == null)
            {
                throw new ValidationErrorException(nameof(ShippingAddress));
            }
            ShippingAddress.Validate();

            if (OrderLines == null || !OrderLines.Any())
            {
                throw new ValidationErrorException(nameof(OrderLines));
            }

            OrderLines.ForEach(o => o.Validate());
        }
        public bool CanPlaceOrder(decimal expectedTotalCost, decimal expectedShippingCost)
        {
            //An order must have at least one line
            if (!OrderLines.Any())
            {
                return(false);
            }

            //All products must be available to order
            foreach (var line in OrderLines)
            {
                if (!_productAvailabilityService.CheckProductAvailability(line.Product.Stockcode, line.Quantity))
                {
                    return(false);
                }
            }

            //The calculated costs must match the expected ones
            CalculateShippingCost();
            CalculateTotalCost();
            if (TotalCost != expectedTotalCost || ShippingCost != expectedShippingCost)
            {
                return(false);
            }

            //if all checks succeeded, return true
            return(true);
        }
Пример #3
0
        /// <summary>
        /// Get the total of the order
        /// </summary>
        /// <returns>The total of the order</returns>
        public decimal GetOrderTotal()
        {
            decimal total = 0M;

            if (OrderLines != null //use OrderLines for lazy loading
                &&
                OrderLines.Any())
            {
                total = OrderLines.Aggregate(total, (t, l) => t += l.TotalLine);
            }

            return(total);
        }
Пример #4
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (OrderLines.Count == 0)
            {
                yield return(new ValidationResult(
                                 "OrderLines should not be empty.",
                                 new[] { "OrderLines" }
                                 ));
            }

            if (OrderLines.Any(orderLine => orderLine.Quantity <= 0))
            {
                yield return(new ValidationResult(
                                 "Quantity should be greater than 0.",
                                 new[] { "OrderLines" }
                                 ));
            }
        }
Пример #5
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (OrderLines.Any(orderLine => orderLine.Quantity <= 0))
            {
                yield return(new ValidationResult(
                                 "Quantity should be greater than 0.",
                                 new[] { "OrderLines" }
                                 ));
            }

            if (OrderLines.Select(orderLine => orderLine.Quantity).Sum() <= 0)
            {
                yield return(new ValidationResult(
                                 "Total quantity should be greater than 0.",
                                 new[] { "OrderLines" }
                                 ));
            }
        }
        internal void PrepareForShipping(PrepareOrderForShipping cmd)
        {
            if (State != OrderState.Pending)
            {
                throw new InvalidOrderStateException(cmd.AggregateId, $"State should be {OrderState.Pending} but is {State}");
            }

            if (State == OrderState.ReadyForShipping)
            {
                return;
            }

            if (!OrderLines.Any())
            {
                throw new InvalidOrderStateException(cmd.AggregateId, $"Order has no order lines");
            }

            RaiseEvent(new OrderReadyForShipping(cmd.AggregateId));
        }
Пример #7
0
 public bool HasOrdered(Product p) => OrderLines.Any(l => l.Product.Equals(p));
Пример #8
0
        public IDictionary GetOrderParams()
        {
            var dictionary = new OrderedDictionary();

            if (!string.IsNullOrEmpty(AcceptReturnUrl))
            {
                dictionary.Add("acceptReturnurl", AcceptReturnUrl);
            }

            if (Amount != 0)
            {
                dictionary.Add("amount", Amount.ToString());
            }

            if (!string.IsNullOrEmpty(CancelReturnUrl))
            {
                dictionary.Add("cancelReturnUrl", CancelReturnUrl);
            }

            if (!string.IsNullOrEmpty(Currency))
            {
                dictionary.Add("currency", Currency);
            }

            if (ExpandOrderInformation)
            {
                dictionary.Add("expandOrderInformation", "1");
            }

            if (!string.IsNullOrEmpty(Merchant))
            {
                dictionary.Add("merchant", Merchant);
            }

            // Because of the sorting rules, order lines needs
            // to come before the headers in the calculation array
            if (OrderLines.Any())
            {
                for (int i = 0; i < OrderLines.Count; i++)
                {
                    int rowNumber = i + 1;
                    dictionary.Add("oiRow" + rowNumber.ToString(), OrderLines[i]);
                }
            }

            if (!string.IsNullOrEmpty(OrderLinesHeader))
            {
                dictionary.Add("oiTypes", OrderLinesHeader);
            }

            if (!string.IsNullOrEmpty(OrderId))
            {
                dictionary.Add("orderid", OrderId);
            }

            // DIBS only accepts "1" for this parameter
            if (IsTest)
            {
                dictionary.Add("test", "1");
            }

            return(dictionary);
        }
Пример #9
0
 public bool HasOrdered(Product p)
 {
     return(OrderLines.Any(l => l.Product.Equals(p)));
 }
Пример #10
0
 /// <summary>
 /// Checks if the provided item exists in the Orders' lines.
 /// </summary>
 /// <param name="itemToCheck">The item to check.</param>
 /// <returns>True if the provided item exists in the Orders' lines; false if not.</returns>
 public bool CheckForItemInOrder(Item itemToCheck)
 {
     return(OrderLines.Any(line => line.Item.Sku == itemToCheck.Sku));
 }