public async Task <IActionResult> OnGetAsync(int id)
        {
            this.Meal = await this.MealsService.GetMealDetailsAsync(id, this.User.Identity.Name);

            if (this.Meal == null)
            {
                return(this.RedirectToPage(PageConstants.MealsIndex));
            }

            return(this.Page());
        }
        public ICollection <MealDetailsViewModel> GetMealsByDate()
        {
            SqlDataReader reader = this.ExecuteReader(
                @"SELECT mealCounts.OrderDate,
                          mealCounts.MealName,
                          mealCounts.MealsCount,
                          c.Username,
                          c.Name AS ClientName
                     FROM
                          (SELECT o.OrderDate,
                                  o.ClientId,
                                  m.Name AS MealName,
                                  COUNT(o.ClientId) AS MealsCount
                             FROM Meals AS m
                             JOIN OrderMeals AS om
                               ON om.MealId = m.Id
                             JOIN Orders AS o
                               ON om.OrderId = o.Id
                            WHERE o.IsCancelled = 0
                            GROUP BY o.OrderDate, m.Name, o.ClientId
                          ) AS mealCounts
                     JOIN Clients AS c
                       ON mealCounts.ClientId = c.Id
                    ORDER BY mealCounts.OrderDate, mealCounts.MealName, mealCounts.ClientId");

            IDictionary <Tuple <DateTime, string>, MealDetailsViewModel> mealsByDate = new Dictionary <Tuple <DateTime, string>, MealDetailsViewModel>();

            using (reader)
            {
                while (reader.Read())
                {
                    DateTime orderDate      = reader.GetDateTime(0);
                    string   mealName       = reader.GetString(1);
                    int      mealsCount     = reader.GetInt32(2);
                    string   clientUsername = reader.GetString(3);
                    string   clientName     = reader.GetString(4);

                    string clientNameRepresentation = this.CombineUsernameAndName(clientUsername, clientName);

                    Tuple <DateTime, string> key = new Tuple <DateTime, string>(orderDate, mealName);

                    if (!mealsByDate.ContainsKey(key))
                    {
                        mealsByDate[key] = new MealDetailsViewModel(orderDate, mealName);
                    }

                    mealsByDate[key].MealsCount += mealsCount;
                    mealsByDate[key].ClientNames.Add(clientNameRepresentation);
                }
            }

            return(mealsByDate.Values);
        }