Exemple #1
0
        public static string GetOutput(TimeOfDay timeOfDay, string inputDishes)
        {
            var meal = new Meal(timeOfDay);
            List<short> dishIndexes;
            if (!Meal.TryParseMealItems(inputDishes, out dishIndexes))
            {
                return "Sorry, I didn't get that.";
            }

            string dishesOutput = string.Empty;
            foreach (var dishIndex in dishIndexes)
            {
                meal.AddMealItem(dishIndex);

                if (meal.IsValid)
                {
                    dishesOutput = GetOutputFromMeal(meal);
                }
                else
                {
                    if (!string.IsNullOrEmpty(dishesOutput))
                    {
                        dishesOutput += ", ";
                    }
                    dishesOutput += "error";
                    break;
                }
            }

            return dishesOutput;
        }
Exemple #2
0
        private static string GetOutputFromMeal(Meal meal)
        {
            string output = string.Empty;
            var sortedMealItems = meal.GetSortedMealItems();
            var groupedMealItems = sortedMealItems.GroupBy(mealItem => mealItem);

            foreach (var mealItemsGroup in groupedMealItems)
            {
                if (!string.IsNullOrEmpty(output))
                {
                    output += ", ";
                }
                var mealItemString = mealItemsGroup.Key + (mealItemsGroup.Count() > 1 ? "(x" + mealItemsGroup.Count() + ")" : string.Empty);
                output += mealItemString;
            }

            return output;
        }