Ejemplo n.º 1
0
        public void Button_Click(object sender, RoutedEventArgs e)
        {
            Button button = sender as Button;
            string type   = button.Tag.ToString();

            BE.Food f  = button.DataContext as BE.Food;
            string  id = f.FoodID.ToString();

            switch (type)
            {
            case "Breakfast":
                RemoveFood(id, BreakfastFoods);
                currentModel.RemoveFoodFromMeal("Breakfast", id, CurrentUser, date);
                break;

            case "Lunch":
                RemoveFood(id, LunchFoods);
                currentModel.RemoveFoodFromMeal("Lunch", id, CurrentUser, date);
                break;

            case "Dinner":
                RemoveFood(id, DinnerFoods);
                currentModel.RemoveFoodFromMeal("Dinner", id, CurrentUser, date);
                break;

            case "Snacks":
                RemoveFood(id, SnacksFoods);
                currentModel.RemoveFoodFromMeal("Snacks", id, CurrentUser, date);
                break;
            }
            CalcToalNutrients();
            CalcRemainingNutrient();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// add food to list in view and database of snack
        /// </summary>
        /// <param name="d"></param>
        /// <param name="e"></param>
        private static void AddFoodSnack(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            VMFoods vM = d as VMFoods;

            BE.Food food = new BE.Food();
            food.Description = (String)e.NewValue;
            food.Date        = DateTime.Parse(vM.Date);
            food.ID          = vM.Id;
            food.ndbo        = "0";
            food.Amount      = "1";
            food.Meal        = "Snack";
            if (food.Description != "" && food.Description != null)
            {
                vM.FoodsSnack.Add(food);
                vM.FoodFunc(food);
            }
            vM.initAllListsOfFood();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// add or remove food to list of snack
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Foods_CollectionChangedSnack(object sender, NotifyCollectionChangedEventArgs e)
 {
     if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
     {
         //הוספה
         BE.Food f = e.NewItems[0] as BE.Food;
         if (f.ID == Id)
         {
             modelFoods.listSnack.Add(e.NewItems[0] as BE.Food);
         }
     }
     if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
     {
         //הסרה
         BE.Food f = e.OldItems[0] as BE.Food;
         if (f.ID == Id)
         {
             modelFoods.listSnack.Remove(f);
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        ///add food to the data base
        /// </summary>
        /// <param name="food"></param>
        public void AddFood(BE.Food food)
        {
            int    count   = 0;
            bool   flag    = false;
            String xmlfood = XmlFood(food.Description);

            food.ndbo = GetKeyOfFood(xmlfood, food.Description);
            BE.Food food2 = new BE.Food();
            using (var db = new BE.AppContext())
            {
                count = db.Foods.Count();
                //if the food exist to this user- upadte the amount
                var qury1 = (from f in db.Foods where f.ID.Equals(food.ID) && f.Date.Equals(food.Date) && f.Description.Equals(food.Description) select f);
                foreach (var item in qury1)
                {
                    food2 = item;
                    int amount = int.Parse(food2.Amount);
                    amount++;
                    food2.Amount = amount.ToString();
                    db.Foods.Remove(item);
                    flag = true;
                }
                db.SaveChanges();

                if (flag)
                {
                    db.Foods.Add(food2);
                }
                //if food not exist - add to db
                if (!flag && food.ndbo != null)
                {
                    food.key = count + 1;
                    db.Foods.Add(food);
                }
                db.SaveChanges();
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 ///substract from amount of specific food
 /// </summary>
 /// <param name="food"></param>
 public void minusAmountFood(BE.Food food)
 {
     bl.minusAmountFood(food);
 }
Ejemplo n.º 6
0
 /// <summary>
 ///add to amount of specific food
 /// </summary>
 /// <param name="food"></param>
 public void addAmountFood(BE.Food food)
 {
     bl.addAmountFood(food);
 }
Ejemplo n.º 7
0
 /// <summary>
 ///add food to data base
 /// </summary>
 /// <param name="food"></param>
 public void AddFood(BE.Food food)
 {
     bl.AddFood(food);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// when that click reduce to food
 /// </summary>
 /// <param name="food"></param>
 public void minusAmountFood(BE.Food food)
 {
     modelFoods.minusAmountFood(food);
     initAllListsOfFood();
 }
Ejemplo n.º 9
0
 /// <summary>
 /// when that click add to food
 /// </summary>
 /// <param name="food"></param>
 public void addAmountFood(BE.Food food)
 {
     modelFoods.addAmountFood(food);
     initAllListsOfFood();
 }
Ejemplo n.º 10
0
 /// <summary>
 /// add food to database
 /// </summary>
 /// <param name="food"></param>
 public void FoodFunc(BE.Food food)
 {
     modelFoods.AddFood(food);
 }