public bool AddMovieFavorites(string userId, string movieId) { try { var lstmovieFavorites = _context.MovieFavorites.FirstOrDefault(x => x.userId == userId && x.movieId.Equals(movieId)); if (lstmovieFavorites != null) { lstmovieFavorites.isFavorites = true; _context.Entry(lstmovieFavorites).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.SaveChanges(); return(true); } // create var movieFavorites = new MovieFavorites() { userId = userId, movieId = movieId, isFavorites = true }; _context.MovieFavorites.Add(movieFavorites); _context.SaveChanges(); return(true); } catch (Exception e) { return(false); } }
[HttpPost] //"Edit" portion of this method is currently unused. Add form will need adjusted to use model components to update. public IActionResult Edit(MovieViewModel selectedMovie) { MovieFavorites favorite = new MovieFavorites { Rating = selectedMovie.FavRating, GroupMembersID = selectedMovie.MemID, SavedMoviesID = selectedMovie.MovID, IsMovie = true, MovieInfo = selectedMovie.Movie }; if (ModelState.IsValid) { if (selectedMovie.MovID == 0) { _context.Movies.Add(selectedMovie.Movie); _context.Favorites.Add(favorite); } else { _context.Movies.Update(selectedMovie.Movie); _context.Favorites.Update(favorite); } _context.SaveChanges(); return(RedirectToAction("ViewAll")); } else { ViewBag.Title = "Add A New Movie"; ViewBag.AddID = "0"; this.LoadViewBag(); return(View("Add")); } }