Beispiel #1
0
        private void generateButton_Click(object sender, EventArgs e)
        {
            try
            {
                var text  = new StringBuilder();
                var start = new DateFormatter(startDateTimePicker.Value);
                var end   = new DateFormatter(endDateTimePicker.Value);
                if (start.DayBeginning() > end.DayEnding())
                {
                    throw new InputExemption("The start date cannot be after the end date.");
                }
                var mealsInDateRange = Globals.AllUsersMeals.Select(mealView => mealView.GetMeal())
                                       .Where(meal => meal.Date > start.DayBeginning() && meal.Date < end.DayEnding()).ToList();

                if (shoppingListRadioButton.Checked)
                {
                    text.AppendLine("Shopping List");
                    text.AppendLine($"For dates {start} to {end}");
                    text.AppendLine();

                    var mealIdArray = mealsInDateRange.Select(meal => meal.Id).ToHashSet <int>().ToArray();
                    Globals.GetListOfIngredientsForMeals(mealIdArray)
                    .ForEach(ingredient => text.AppendLine($"*\t{ingredient}"));

                    reportTextBox.Text = text.ToString();
                }

                if (topTenRadioButton.Checked)
                {
                    text.AppendLine($"Top Recipes for dates {start} to {end}");
                    text.AppendLine("(Max 10)");
                    text.AppendLine();
                    text.AppendLine("Recipe Title\t\t|  Times Recipe Used");
                    text.AppendLine("-----------------------------------------------------------------------------------");

                    var groupOfRecipes = Globals.GetMealsRecipes(mealsInDateRange).GroupBy(recipe => recipe.Title)
                                         .OrderByDescending(recipe => recipe.Count()).Take(10);

                    foreach (var group in groupOfRecipes)
                    {
                        if (group.Key.Length < 8)
                        {
                            text.AppendLine($"{group.Key}\t\t\t|    {group.Count()}");
                        }
                        else
                        {
                            text.AppendLine($"{group.Key}\t\t|    {group.Count()}");
                        }
                    }

                    reportTextBox.Text = text.ToString();
                }
            }
            catch (InputExemption error)
            {
                MessageBox.Show(error.Message, "Instructions", MessageBoxButtons.OK);
            }
        }
Beispiel #2
0
        private void updateMealsList(DateFormatter dateFormatter)
        {
            DateTime start;
            DateTime end;

            if (dayRadioButton.Checked)
            {
                start = dateFormatter.DayBeginning();
                end   = dateFormatter.DayEnding();
            }
            else if (weekRadioButton.Checked)
            {
                start = dateFormatter.WeekBeginning();
                end   = dateFormatter.WeekEnding();
            }
            else
            {
                start = dateFormatter.MonthBeginning();
                end   = dateFormatter.MonthEnding();
            }
            MealsList.Clear();
            Globals.AllUsersMeals
            .Where(mealView => mealView.GetMeal().Date >= start && mealView.GetMeal().Date <= end).ToList()
            .ForEach(mealView => MealsList.Add(mealView));
        }
Beispiel #3
0
        public void DateFormatterReturnsCorrectDateWhenDayBeginningCalled()
        {
            //Arrange
            var date = new DateTime(2021, 3, 14, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
            //Act
            var newDateFormatter = new DateFormatter(date);
            var actual           = newDateFormatter.DayBeginning();
            var expected         = new DateTime(2021, 3, 14);

            //Assert
            Assert.AreEqual(expected, actual);
        }