Esempio n. 1
0
        public static void WriteConsoleOutput(string[] args, IOutputWriter writer, IPriceRepository priceRep, IPromotionRepository promoRep)
        {
            //validate argument.
            string argument = string.Empty;

            if (!args.Count().Equals(1))
            {
                var message = string.Format(AppSettings.Get <string>("MissingArgText"), AppSettings.Get <char>("ItemSeparator"), AppSettings.Get <char>("QuantitySeparator"));
                writer.WriteLine(message);
                argument = writer.ReadLine();
            }
            else
            {
                argument = args[0];
            }
            //prepare data
            if (!string.IsNullOrEmpty(argument))
            {
                var itemList = argument.Split(AppSettings.Get <char>("ItemSeparator")).ToList();

                var           output  = new StringBuilder();
                BasketService service = new BasketService(priceRep, promoRep);
                service.SetBasket(itemList);
                service.CalculatePromotions();
                writer.WriteLine(string.Format("Total Before discount: {0}", service.SubTotal.ToString("c")));
                writer.WriteLine("Total: " + service.Total.ToString("c"));
            }
        }