Beispiel #1
0
        public async Task <IActionResult> MovieList(CreateMovieListViewModel model)
        {
            ViewData["Message"] = "Create a new list for movies";

            var dbGenres = await _appDbContext.TraktMovieGenres.ToListAsync();

            var dbCertifications = await _appDbContext.TraktMovieCertifications.ToListAsync();

            var dbCountryCodes = await _appDbContext.CountryCodes.OrderBy(x => x.Name).ToListAsync();

            var dbLanguageCodes = await _appDbContext.LanguageCodes.OrderBy(x => x.Code).ToListAsync();

            model.Genres                = new MultiSelectList(dbGenres, nameof(TraktMovieGenre.Slug), nameof(TraktMovieGenre.Slug));
            model.Certifications        = new MultiSelectList(dbCertifications, nameof(TraktMovieCertification.Slug), nameof(TraktMovieCertification.Description));
            model.Countries             = new MultiSelectList(dbCountryCodes, nameof(CountryCode.Code), nameof(CountryCode.Name));
            model.Languages             = new MultiSelectList(dbLanguageCodes, nameof(LanguageCode.Code), nameof(LanguageCode.Description));
            model.Translations          = new MultiSelectList(dbLanguageCodes, nameof(LanguageCode.Code), nameof(LanguageCode.Description));
            model.ReverseGenres         = new MultiSelectList(dbGenres, nameof(TraktMovieGenre.Slug), nameof(TraktMovieGenre.Name));
            model.ReverseCertifications = new MultiSelectList(dbCertifications, nameof(TraktMovieCertification.Slug), nameof(TraktMovieCertification.Description));
            model.ReverseCountries      = new MultiSelectList(dbCountryCodes, nameof(CountryCode.Code), nameof(CountryCode.Name));
            model.ReverseLanguages      = new MultiSelectList(dbLanguageCodes, nameof(LanguageCode.Code), nameof(LanguageCode.Description));
            model.ReverseTranslations   = new MultiSelectList(dbLanguageCodes, nameof(LanguageCode.Code), nameof(LanguageCode.Description));

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var result = await _traktService.Create(new TraktList()
            {
                Name                               = model.Name,
                Query                              = model.Query ?? "",
                Type                               = ListType.Movie,
                Filter_Years                       = model.Filter_Years,
                Filter_Ratings                     = model.Filter_Ratings,
                Filter_Runtimes                    = model.Filter_Runtimes,
                SearchByAlias                      = model.SearchByAlias,
                SearchByBiography                  = model.SearchByBiography,
                SearchByDescription                = model.SearchByDescription,
                SearchByName                       = model.SearchByName,
                SearchByOverview                   = model.SearchByOverview,
                SearchByPeople                     = model.SearchByPeople,
                SearchByTitle                      = model.SearchByTitle,
                SearchByTranslations               = model.SearchByTranslations,
                SearchByTagline                    = model.SearchByTagline,
                Filter_Genres                      = new GenresCommonFilter(model.Filter_Genres),
                Filter_Languages                   = new LanguagesCommonFilter(model.Filter_Languages),
                Filter_Translations                = new TranslationsBasicFilter(model.Filter_Translations),
                Filter_Certifications_Movie        = new CertificationsMovieFilter(model.Filter_Certifications),
                Filter_Countries                   = new CountriesCommonFilter(model.Filter_Countries),
                ReverseFilter_Genres               = new GenresCommonFilter(model.ReverseFilter_Genres),
                ReverseFilter_Languages            = new LanguagesCommonFilter(model.ReverseFilter_Languages),
                ReverseFilter_Translations         = new TranslationsBasicFilter(model.ReverseFilter_Translations),
                ReverseFilter_Certifications_Movie = new CertificationsMovieFilter(model.ReverseFilter_Certifications),
                ReverseFilter_Countries            = new CountriesCommonFilter(model.ReverseFilter_Countries),
                Owner                              = await _userManager.GetUserAsync(User)
            });

            Hangfire.BackgroundJob.Enqueue <ProcessMovieListBackgroundJob>(x => x.Execute(result.Id));

            return(RedirectToAction(nameof(MovieList)));
        }