TraktPlugin.GUI.GUICommon.RateMovie C# (CSharp) Méthode

RateMovie() static private méthode

static private RateMovie ( TraktMovieSummary movie ) : bool
movie TraktPlugin.TraktAPI.DataStructures.TraktMovieSummary
Résultat bool
        internal static bool RateMovie(TraktMovieSummary movie)
        {
            var rateObject = new TraktSyncMovieRated
            {
                Ids = new TraktMovieId
                {
                    Trakt = movie.Ids.Trakt,
                    Imdb = movie.Ids.Imdb.ToNullIfEmpty(),
                    Tmdb = movie.Ids.Tmdb
                },
                Title = movie.Title,
                Year = movie.Year,
                RatedAt = DateTime.UtcNow.ToISO8601()
            };

            int? prevRating = movie.UserRating();
            int newRating = 0;

            newRating = GUIUtils.ShowRateDialog<TraktSyncMovieRated>(rateObject);
            if (newRating == -1) return false;

            // If previous rating not equal to current rating then
            // update skin properties to reflect changes
            if (prevRating == newRating)
                return false;

            if (prevRating == null || prevRating == 0)
            {
                // add to ratings
                TraktCache.AddMovieToRatings(movie, newRating);
                movie.Votes++;
            }
            else if (newRating == 0)
            {
                // remove from ratings
                TraktCache.RemoveMovieFromRatings(movie);
                movie.Votes--;
            }
            else
            {
                // rating changed, remove then add
                TraktCache.RemoveMovieFromRatings(movie);
                TraktCache.AddMovieToRatings(movie, newRating);
            }

            // update ratings until next online update
            // if we have the ratings distribution we could calculate correctly
            if (movie.Votes == 0)
            {
                movie.Rating = 0;
            }
            else if (movie.Votes == 1 && newRating > 0)
            {
                movie.Rating = newRating;
            }

            return true;
        }