Exemplo n.º 1
0
        public async Task <IActionResult> ShowList()
        {
            ViewData["Message"] = "Create a new list for shows";

            var dbGenres = await _traktShowRepository.GetGenres();

            var dbStatus = await _traktShowRepository.GetStatuses();

            var dbNetworks = await _traktShowRepository.GetNetworks();

            var dbCertifications = await _traktShowRepository.GetCertifications();

            var dbCountryCodes = await _traktCodesRepository.GetCountryCodes();

            var dbLanguageCodes = await _traktCodesRepository.GetLanguageCodes();

            var model = new CreateShowListViewModel
            {
                Genres                = new MultiSelectList(dbGenres, nameof(TraktShowGenre.Slug), nameof(TraktShowGenre.Name)),
                Certifications        = new MultiSelectList(dbCertifications, nameof(TraktShowCertification.Slug), nameof(TraktShowCertification.Description)),
                Countries             = new MultiSelectList(dbCountryCodes, nameof(CountryCode.Code), nameof(CountryCode.Name)),
                Languages             = new MultiSelectList(dbLanguageCodes, nameof(LanguageCode.Code), nameof(LanguageCode.Description)),
                Translations          = new MultiSelectList(dbLanguageCodes, nameof(LanguageCode.Code), nameof(LanguageCode.Description)),
                Networks              = new MultiSelectList(dbNetworks, nameof(TraktShowNetwork.Name), nameof(TraktShowNetwork.Name)),
                Status                = new MultiSelectList(dbStatus, nameof(TraktShowStatus.Name), nameof(TraktShowStatus.Name)),
                ReverseGenres         = new MultiSelectList(dbGenres, nameof(TraktShowGenre.Slug), nameof(TraktShowGenre.Name)),
                ReverseCertifications = new MultiSelectList(dbCertifications, nameof(TraktShowCertification.Slug), nameof(TraktShowCertification.Description)),
                ReverseCountries      = new MultiSelectList(dbCountryCodes, nameof(CountryCode.Code), nameof(CountryCode.Name)),
                ReverseLanguages      = new MultiSelectList(dbLanguageCodes, nameof(LanguageCode.Code), nameof(LanguageCode.Description)),
                ReverseTranslations   = new MultiSelectList(dbLanguageCodes, nameof(LanguageCode.Code), nameof(LanguageCode.Description)),
                ReverseNetworks       = new MultiSelectList(dbNetworks, nameof(TraktShowNetwork.Name), nameof(TraktShowNetwork.Name)),
                ReverseStatus         = new MultiSelectList(dbStatus, nameof(TraktShowStatus.Name), nameof(TraktShowStatus.Name)),
            };

            return(View(model));
        }
        public async Task Execute(PerformContext context)
        {
            var result = await _traktClient.Certifications.GetShowCertificationsAsync();

            if (result.IsSuccess)
            {
                var currentCertifications = await _traktShowRepository.GetCertifications();

                foreach (var traktCertification in result.Value.US)
                {
                    var currentCertification = currentCertifications.FirstOrDefault(x => x.Slug != traktCertification.Slug);

                    if (currentCertification == null)
                    {
                        await _traktShowRepository.CreateCertification(new TraktShowCertification()
                        {
                            Name        = traktCertification.Name,
                            Description = traktCertification.Description,
                            Slug        = traktCertification.Slug
                        });
                    }
                }
            }
        }