Esempio n. 1
0
 /// <summary>
 /// Fuction that gets a meal and a user and add the meal to the user
 /// </summary>
 /// <param name="meal"></param>
 /// <param name="currentUser"></param>
 public void AddMeal(BE.Meal meal, BE.User currentUser)
 {
     using (FoodBackDBEntities FBContext = new FoodBackDBEntities())
     {
         FBContext.Meals.Add(meal);
         var user = FBContext.Users.Single(u => u.EmailAddress.Equals(currentUser.EmailAddress));
         user.Meals.Add(meal);
         meal.Users.Add(user);
         FBContext.SaveChanges();
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Function that gets a user, type of meal and food to add to user's meal in a specific date and type of meal
 /// </summary>
 /// <param name="meal"></param>
 /// <param name="currentUser"></param>
 /// <param name="food"></param>
 public void AddFoodForMealPerUser(string meal, User currentUser, Food food, DateTime date)
 {
     using (FoodBackDBEntities FBContext = new FoodBackDBEntities())
     {
         var user = FBContext.Users.Single(u => u.EmailAddress.Equals(currentUser.EmailAddress));
         foreach (Meal m in user.Meals)
         {
             if (m.MealDate.Equals(date) && m.Type.Equals(meal))
             {
                 m.Foods.Add(food);
                 food.Meals.Add(m);
                 FBContext.SaveChanges();
                 return;
             }
         }
         Meal m1 = new BE.Meal {
             Type = meal, MealDate = date
         };
         m1.Foods.Add(food);
         AddMeal(m1, user);
     }
 }