public async Task <ActionResult> AddToFavourite(int cocktailId) { if (cocktailId == 0) { return(BadRequest()); } var userId = User.GetUserId(); var cocktail = await _coctailRepository.GetCoctailByIdAsync(cocktailId); var user = await _userRepository.GetUserById(userId); if (user == null || cocktail == null) { return(NotFound("User or cocktail not found")); } var favouriteCocktail = new FavouriteCoctail { AppUser = user, AppUserId = userId, CoctailId = cocktailId, Coctail = cocktail }; if (await _coctailRepository.AddCocktailToFavourite(favouriteCocktail)) { return(Ok(JsonSerializer.Serialize("Cocktail has been added to favourite"))); } return(BadRequest(JsonSerializer.Serialize("Something went wrong..."))); }
public async Task <bool> DeleteFromFavouritesAsync(FavouriteCoctail favouriteCoctail) { _context.FavouriteCoctails.Remove(favouriteCoctail); return(await _context.SaveChangesAsync() > 0); }
public async Task <bool> AddCocktailToFavourite(FavouriteCoctail favouriteCoctail) { await _context.FavouriteCoctails.AddAsync(favouriteCoctail); return(await _context.SaveChangesAsync() > 0); }