Exemplo n.º 1
0
        static void UpdateMeals()
        {
            var mealsRepos = MealsRepos.GetAll();

            foreach (var meal in mealsRepos)
            {
                var ingredientsRepos = IngredientsRepos.GetByID(meal.ID.Value);

                int n = ingredientsRepos.Count;

                int?   ID     = meal.ID;
                string Name   = meal.Name;
                double Kcal   = 0;
                double Prot   = 0;
                double Fat    = 0;
                double Carbs  = 0;
                double Weight = 0;
                int[]  Type   = new int[n];

                Console.WriteLine($"Meal no. {meal.ID.Value} - {Name}");

                for (int j = 0; j < n; j++)
                {
                    var weight = ingredientsRepos[j].Weight;

                    Kcal   += ingredientsRepos[j].Kcal * weight * 0.01;
                    Prot   += ingredientsRepos[j].Protein * weight * 0.01;
                    Fat    += ingredientsRepos[j].Fat * weight * 0.01;
                    Carbs  += ingredientsRepos[j].Carbs * weight * 0.01;
                    Weight += ingredientsRepos[j].Weight;

                    var t = ingredientsRepos[j].Type;

                    if (t == Projekt.Properties.Resources.normal)
                    {
                        Type[j] = 0;
                    }
                    if (t == Projekt.Properties.Resources.vegetarian)
                    {
                        Type[j] = 1;
                    }
                    if (t == Projekt.Properties.Resources.vegan)
                    {
                        Type[j] = 2;
                    }

                    //Console.WriteLine(Type[j]);
                }
                var type = Type.Min().ToString();

                //Console.WriteLine($"min: {type}");

                var newMeal = new Meals(Name, Weight, Kcal, Prot, Fat, Carbs, type);

                MealsRepos.Update(newMeal, ID);
            }
        }
Exemplo n.º 2
0
        public MealsPage()
        {
            InitializeComponent();
            var mealsRepos = MealsRepos.GetAll();

            Meals_listview.ItemsSource = mealsRepos;

            if (Login.LOGIN_STATUS)
            {
                Meals_stackpanel.IsEnabled = true;
            }
        }
Exemplo n.º 3
0
        private void GenerateMeals_button_Click(object sender, RoutedEventArgs e)
        {
            Users user = Login.CurrentUser;

            Debug.WriteLine(user);

            var mealsCount    = Convert.ToInt32(user.MealsCount);
            var dailyCalories = Convert.ToDouble(user.Kcal);
            var dietType      = Convert.ToInt32(user.DietType);
            var goal          = Convert.ToInt32(user.Goal);
            var weight        = Convert.ToDouble(user.Weight);

            Meals meals = new Meals(mealsCount, dailyCalories,
                                    dietType, goal, weight);

            var oneDay = meals.ListOfMeals;

            Debug.WriteLine("\n\n");
            var ListOfMeals = MealsRepos.GetAll();

            var login = user.Login;

            DietRepos.Delete(login);
            int i = 1;

            foreach (var meal in oneDay)
            {
                var result = MathOperations.GetMostSimilarMeal(meal, ListOfMeals, user.DietType.ToString());
                Debug.WriteLine(meal);
                Debug.WriteLine(result);

                var mealID = result.ID;
                var nr     = i.ToString();

                DietRepos.Insert(new Diet(login, Convert.ToInt32(mealID), nr));
                i++;
            }

            Meals_listview.ItemsSource = MealsRepos.GetByLogin(Login.UserLogin);
            Meals_listview.Items.Refresh();
        }