Пример #1
0
 /// <summary>
 /// Checks if the order is valid.
 /// The quantity of the ordered article has to be more than 0 and less than 10000.
 /// </summary>
 /// <param name="order">The order</param>
 /// <returns>True, if order is valid</returns>
 public static bool IsValidOrder(Order order)
 {
     bool isValid = true;
     if (order.Quantity < 1 || order.Quantity > 10000)
     {
         isValid = false;
     }
     return isValid;
 }
        private static bool CalculatePrice(Order order)
        {
            bool result = true;

            var priceCalculation = new PriceCalculation();
            var price = priceCalculation.CalculatePrice(order.ArticleId, order.Quantity);
            if (price == -1m)
            {
                result = false;
            }

            return result;
        }
        /// <summary>
        /// This method is a facade which simplifies the placement of an order. 
        /// It orchestrates the steps needed to place an order.
        /// The OrderPlacement process consists of a validation, price calculation and the storage of the order.
        /// </summary>
        /// <param name="articleId">The article id</param>
        /// <param name="quantity">The quantity</param>
        /// <returns>True if order was succesfully stored and will be shipped</returns>
        public bool PlaceOrder(string articleId, int quantity)
        {
            Order order = new Order
            {
                ArticleId = articleId,
                Quantity = quantity
            };

            // Validate order
            bool result = OrderValidator.IsValidOrder(order);

            // Calculate Price
            result = result && CalculatePrice(order);

            // Place Order
            result = result & OrderStorage.PlaceOrder(order);

            return result;
        }
Пример #4
0
 /// <summary>
 /// Dummy implementation which represents the order placing
 /// </summary>
 /// <param name="order">The order to store</param>
 /// <returns>True, if order has been successfully placed</returns>
 public static bool PlaceOrder(Order order)
 {
     // Store Order for further processing
     return true;
 }