Example #1
0
 public void AddMeal(MealModel mealModel)
 {
     using (var context = new HealthContext())
     {
         var day = context.Days.FirstOrDefault(d => d.Created == mealModel.Date);
         var meal = new Meal
         {
             DayId = day.Id,
             MealNumber = mealModel.MealNumber,
             MealEntries = mealModel.MealEntries
         };
         context.Add(meal);
         context.MealEntries.AddRange(meal.MealEntries);
         context.SaveChanges();
     }
 }
Example #2
0
 private void SeedMeal(IBusinessService businessService)
 {
     var currentDate = businessService.GetMostRecentDay();
     var meal = new MealModel
     {
         Date = currentDate.Date,
         MealNumber = 1,
         MealEntries = new List<MealEntry> {
             new MealEntry
             {
                 MealEntryNumber = 0,
                 Calories = 120,
                 Food= businessService.GetFoodByName("chicken")
             },
             new MealEntry
             {
                 MealEntryNumber = 1,
                 Calories = 184,
                 Food= businessService.GetFoodByName("eggs")
             }}
     };
     businessService.AddMeal(meal);
     meal.MealNumber = 2;
     meal.MealEntries.FirstOrDefault().Id = 0;
     meal.MealEntries.LastOrDefault().Id = 0;
     businessService.AddMeal(meal);
 }