public ActionResult RateMovie(RatingViewModel ratingViewModel) { Rating rating = new Rating(); List <StreamingService> st = _db.GetAllStreamingServices(); foreach (StreamingService s in st) { foreach (User u in s.Users) { if (u.UserName == Session["username"].ToString()) { rating.User = u; _db.Entry(_db.Movies.Find(ratingViewModel.MOvie.ID)).Collection(m => m.Ratings).Load(); if (_db.Movies.Find(ratingViewModel.MOvie.ID) is Serie) { rating.is_following = ratingViewModel.is_following; _db.Movies.Find(ratingViewModel.MOvie.ID).AddRating(rating); _db.SaveChanges(); } else { rating.Score = ratingViewModel.Rating.Score; Movie movie = _db.Movies.Find(ratingViewModel.MOvie.ID); movie.AddRating(rating); _db.SaveChanges(); } } } } return(RedirectToAction("Movies", new { Id = _db.Movies.Find(ratingViewModel.MOvie.ID).StreamingId })); }