public async void GivenTheFoodItemIsAssignedToAMealAndASnack() { var user = new VerdureUser("Sally"); using (var context = VerdureInMemoryContext.Context) { context.Users.Add(user); await context.SaveChangesAsync(); user = context.Users.Find(user.Id); _meal = new EfcMeal(user); context.Meals.Add(_meal); _snack = new EfcSnack(user); context.Snacks.Add(_snack); var fooditem = context.FoodItems.Find(_fooditem.Id); var secondfooditem = context.FoodItems.Find(_alternatefooditem.Id); _snack.SetFoodItem(fooditem); _meal.AddFoodItem(fooditem); _meal.AddFoodItem(secondfooditem); await context.SaveChangesAsync(); } }
public async Task SubmitTask() { _snack.SetFoodItem(FoodItem); if (_snack != null && _snack.Food != null) { _snackRepository.GetVerdureContext().Set <EfcFoodItem>().Attach(FoodItem); _snackRepository.GetVerdureContext().Set <VerdureUser>().Attach(_settingService.CurrentUser as VerdureUser); await _snackRepository.Create(_snack); await _snackRepository.SaveAsync(); await _navigationService.NavigateAsync("/" + typeof(CentralPage).Name); } }