private void GeneratePersonalizedDiet_Click(object sender, EventArgs e)
        {
            SystemUser.diet = new Diet();
            QuestionCounter = 0;
            SystemUser.diet.ChoosenProducts.Clear();

            List <Question>          QuestionList = new List <Question>();
            IEnumerable <categories> categoriesList;
            IEnumerable <products>   productsList;
            IEnumerable <meals>      mealsConsumptionTime;

            using (var dbConnection = new Entities())
            {
                categoriesList       = (from b in dbConnection.categories select b).ToList();
                productsList         = (from c in dbConnection.products select c).ToList();
                mealsConsumptionTime = (from d in dbConnection.meals select d).ToList();
            }

            foreach (var category in categoriesList)
            {
                var currentCategoryProducts = from c in productsList where c.id_category == category.id_category select c;
                QuestionList.Add(new Question(category.id_category, category.nameCategory, currentCategoryProducts.ToList()));
            }

            QuestionWindow questionWindow = new QuestionWindow(QuestionList, SystemUser, mealsConsumptionTime.ToList())
            {
                StartPosition = FormStartPosition.CenterParent
            };

            questionWindow.ShowDialog();

            CalculateKcalAndPrepareDiet();

            SystemUser.diet.GenerateDiet();

            YourMeals showMeals = new YourMeals(SystemUser);

            showMeals.ShowDialog();
        }
Example #2
0
        private void NextCategory_Click(object sender, EventArgs e)
        {
            int categorySelectCounter = 0;

            foreach (var categoryItem in categoryValue)
            {
                if (!categorySelect[categorySelectCounter].Checked)
                {
                    //injectedProducts.RemoveAt(categorySelectCounter);
                    categorySelectCounter++;
                    continue;
                }

                var eatingTimesForCurrentProduct = (from c in injectedMealsConsumptionTime
                                                    where c.id_product == injectedProducts[categorySelectCounter].ID
                                                    select c).ToList();

                systemUser.diet.ChoosenProducts.Add(new Product()
                {
                    ID           = injectedProducts[categorySelectCounter].ID,
                    Carbs        = injectedProducts[categorySelectCounter].Carbs,
                    Protein      = injectedProducts[categorySelectCounter].Protein,
                    CategoryName = injectedProducts[categorySelectCounter].CategoryName,
                    MacroElement = injectedProducts[categorySelectCounter].MacroElement,
                    Fat          = injectedProducts[categorySelectCounter].Fat,
                    Kcal         = injectedProducts[categorySelectCounter].Kcal,
                    Name         = injectedProducts[categorySelectCounter].Name,
                    Rating       = int.Parse(categoryItem.Value.Text),
                });

                if (eatingTimesForCurrentProduct.Count != 0)
                {
                    systemUser.diet.ChoosenProducts.Last().ConsumptionTime[(int)FoodConsumptionTime.FirstMeal] =
                        eatingTimesForCurrentProduct[0].first_meal;
                    systemUser.diet.ChoosenProducts.Last().ConsumptionTime[(int)FoodConsumptionTime.SecondMeal] =
                        eatingTimesForCurrentProduct[0].second_meal;
                    systemUser.diet.ChoosenProducts.Last().ConsumptionTime[(int)FoodConsumptionTime.ThirdMeal] =
                        eatingTimesForCurrentProduct[0].third_meal;
                    systemUser.diet.ChoosenProducts.Last().ConsumptionTime[(int)FoodConsumptionTime.FourthMeal] =
                        eatingTimesForCurrentProduct[0].fourth_meal;
                    systemUser.diet.ChoosenProducts.Last().ConsumptionTime[(int)FoodConsumptionTime.FifthMeal] =
                        eatingTimesForCurrentProduct[0].fifth_meal;
                }


                categorySelectCounter++;
            }

            MainWindow.QuestionCounter++;
            if (MainWindow.QuestionCounter < questions.Count)
            {
                QuestionWindow nextQuestionWindow = new QuestionWindow(questions, systemUser, injectedMealsConsumptionTime)
                {
                    StartPosition = FormStartPosition.CenterParent
                };

                this.Hide();
                nextQuestionWindow.ShowDialog();
                this.Close();
            }
            else
            {
                this.Close();
            }
        }