public void DisplayProducts()
        {
            List <ProductDTO> products = productService.GetProducts();

            Console.WriteLine();
            Console.WriteLine("Products:");
            Console.WriteLine();

            reportHandler.SetupColumns(30, 10, 30);

            reportHandler.AddColumns("Name", "Code", "Promotion");

            reportHandler.AddColumns('-', "", "", "");

            foreach (ProductDTO product in products)
            {
                string promotionDisplay = string.Empty;

                if (product.Promotions.Count > 0)
                {
                    // we assume the service will only return one active promotion (promotions are stored in the DB)
                    PromotionDTO promotion = product.Promotions.First();

                    if (promotion.PromotionCode == Constants.PromotionType.Discount)
                    {
                        promotionDisplay = String.Format("Buy {0}, Discount Next {1} to {2:P}", promotion.Quantity, promotion.ApplyTo, promotion.Amount);
                    }

                    else if (promotion.PromotionCode == Constants.PromotionType.Price)
                    {
                        promotionDisplay = String.Format("Buy {0} for {1:C}", promotion.Quantity, promotion.Amount);
                    }
                }

                reportHandler.AddColumns(product.Description, product.Code, promotionDisplay);
            }

            reportHandler.GenerateReport();
        }
Example #2
0
        private void DisplayInvoice(OrderDTO order)
        {
            List <ProductDTO> products = productService.GetProducts();

            Console.WriteLine("".PadRight(30, '-') + "RECEIPT" + "".PadRight(30, '-'));

            Console.WriteLine();
            Console.WriteLine("Order Number: " + order.Id);
            Console.WriteLine("Date: " + order.CreatedDate.ToString());
            Console.WriteLine();
            Console.WriteLine();

            reportHandler.SetupColumns(30, 10, 30);

            reportHandler.AddColumns("Product", "Price", "Promotion Applied");

            reportHandler.AddColumns('-', "", "", "");

            decimal total = 0;

            foreach (OrderItemDTO orderItem in order.OrderItems)
            {
                ProductDTO product = products.First(p => p.Code == orderItem.ProductCode);

                reportHandler.AddColumns(product.Description, orderItem.Price.ToString("C"),
                                         (orderItem.PromotionApplied ? "Yes" : "No"));

                total += orderItem.Price;
            }

            reportHandler.AddRow();

            reportHandler.AddColumns("Total", total.ToString("C"));

            reportHandler.GenerateReport();
        }