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

RateShow() static private méthode

static private RateShow ( TraktShowSummary show ) : bool
show TraktPlugin.TraktAPI.DataStructures.TraktShowSummary
Résultat bool
        internal static bool RateShow(TraktShowSummary show)
        {
            var rateObject = new TraktSyncShowRated
            {
                Ids = new TraktShowId
                {
                    Trakt = show.Ids.Trakt,
                    Imdb = show.Ids.Imdb.ToNullIfEmpty(),
                    Tmdb = show.Ids.Tmdb,
                    TvRage = show.Ids.TvRage,
                    Tvdb = show.Ids.Tvdb
                },
                Title = show.Title,
                Year = show.Year,
                RatedAt = DateTime.UtcNow.ToISO8601()
            };

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

            newRating = GUIUtils.ShowRateDialog<TraktSyncShowRated>(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.AddShowToRatings(show, newRating);
                show.Votes++;
            }
            else if (newRating == 0)
            {
                // remove from ratings
                TraktCache.RemoveShowFromRatings(show);
                show.Votes--;
            }
            else
            {
                // rating changed, remove then add
                TraktCache.RemoveShowFromRatings(show);
                TraktCache.AddShowToRatings(show, newRating);
            }

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

            return true;
        }