예제 #1
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     Intake newIntake = new Intake();
     newIntake.DayIntake = MainPage.SelectedDay; //tuleeko staattisuudesta ongelmia???
     newIntake.Grams = (int)amountchanger.Grams;
     newIntake.Calories = (int)amountchanger.Cals;
     App.ViewModel.AddIntake(newIntake, item);
 }
        public void DeleteIntake(Intake intakeForDelete)
        {
            // Remove the to-do item from the "all" observable collection.
            intakeForDelete.IngredientOfIntake.Intakes.Remove(intakeForDelete);
            intakeForDelete.DayIntake.Intakes.Remove(intakeForDelete);
            AllIntakes.Remove(intakeForDelete);

            // Remove the to-do item from the data context.
            calorieCounterDB.Intakes.DeleteOnSubmit(intakeForDelete);

            // Save changes to the database.
            calorieCounterDB.SubmitChanges();
        }
        /// <summary>
        /// Adds an intake to viewmodel and db,
        /// intake must contain ref to day, grams and calories
        /// </summary>
        /// <param name="newIntake"></param>
        /// <param name="ing"></param>
        public void AddIntake(Intake newIntake, Item ing)
        {
            Ingredient newIngredient = this.getIngredient(ing.Id);
            if (newIngredient == null)
            {
                newIngredient = new Ingredient();
                newIngredient.ItemId = ing.Id;
                newIngredient.Name = ing.Name;
                newIngredient.Calories = ing.Calories;
                newIngredient.Fat = ing.Fat;
                newIngredient.Carbohydrates = ing.Carbohydrates;
                newIngredient.Protein = ing.Protein;
                newIngredient.Portion = ing.Portion;
                newIngredient.PortionCalories = ing.PortionCalories;
                newIngredient.Portionweight = ing.Portionweight;
                this.AddIngredient(newIngredient);
            }

            newIntake.IngredientOfIntake = newIngredient;
            newIntake.DayIntake.Intakes.Add(newIntake); //voiko tää toimia???
            newIntake.DayIntake.Total = newIntake.DayIntake.Intakes.Select(i => i.Calories).Sum();
            MessageBox.Show("Total " + newIntake.DayIntake.Total);
            newIngredient.Intakes.Add(newIntake);
            AddIntake(newIntake);
            MessageBox.Show("lisätään " + newIntake.IngredientOfIntake.Name);
            //pitäis vielä päivättää dayslist
        }
        // Add a to-do item to the database and collections.
        public void AddIntake(Intake newIntake)
        {
            // Add a to-do item to the data context.
            calorieCounterDB.Intakes.InsertOnSubmit(newIntake);

            // Save changes to the database.
            calorieCounterDB.SubmitChanges();

            // Add a to-do item to the "all" observable collection.
            AllIntakes.Add(newIntake);
        }
 // Called during a remove operation
 private void detach_Intake(Intake intake)
 {
     NotifyPropertyChanging("Intake");
     intake.DayIntake = null;
 }
 // Called during an add operation
 private void attach_Intake(Intake intake)
 {
     NotifyPropertyChanging("Intake");
     intake.DayIntake = this;
 }
 // Called during a remove operation
 private void detach_Intake(Intake intake)
 {
     NotifyPropertyChanging("Intake");
     intake.IngredientOfIntake = null;
 }
 // Called during an add operation
 private void attach_Intake(Intake intake)
 {
     NotifyPropertyChanging("Intake");
     intake.IngredientOfIntake = this;
 }