public async Task <IActionResult> AddToFavourite(Guid id) { Recipe recipe = await recipeRepository.FindAsync(r => r.Id == id); User user = await _signInManager.UserManager.GetUserAsync(User); Favourite favourite = new Favourite { Id = Guid.NewGuid(), Recipe = recipe, User = user }; recipe.Favourites.Add(favourite); recipeRepository.Update(recipe); return(PartialView("_RecipeDetails", new RecipeDetailsViewModel { Recipe = recipe, DidUserRate = recipe.Ratings.Any(rating => rating.User == user), IsInUserFavourites = true })); }
public async Task <IActionResult> RemoveFromFavourite(Guid id) { Recipe recipe = await recipeRepository.FindAsync(r => r.Id == id); User user = await _signInManager.UserManager.GetUserAsync(User); Favourite favourite = recipe.Favourites.Where(f => f.User == user).FirstOrDefault(); if (favourite != null) { favouriteRepository.Remove(favourite); } return(PartialView("_RecipeDetails", new RecipeDetailsViewModel { Recipe = recipe, DidUserRate = recipe.Ratings.Any(rating => rating.User == user), IsInUserFavourites = false })); }