예제 #1
0
        public async Task <ActionResult> Category(int id, string seoName)
        {
            var quizCategory = await TriviaService.GetQuizCategoryAsync(id);

            if (quizCategory == null)
            {
                return(new HttpNotFoundResult());
            }

            string expectedSeoName = quizCategory.ToSEOName();

            if (seoName != expectedSeoName)
            {
                return(RedirectToAction("category", new { id = id, seoName = expectedSeoName }));
            }

            await SetNotificationsAsync();

            var currentUserId = User.Identity.GetUserId();

            TriviaCategoryViewModel viewModel = new TriviaCategoryViewModel();

            var quizzesInCategory = await TriviaService.GetQuizzesInCategoryAsync(id);

            viewModel.Quizzes = Mapper.Map <IReadOnlyCollection <Quiz>, IReadOnlyCollection <QuizOverviewViewModel> >(quizzesInCategory);

            viewModel.QuizCategories = await TriviaService.GetQuizCategoriesAsync();

            viewModel.TrendingQuizzes = await GetTrendingQuizzesAsync();

            viewModel.PopularQuizzes = await GetPopularQuizzesAsync();

            viewModel.RecentlyCompletedQuizzes = await TriviaService.GetUsersCompletedQuizzesAsync(currentUserId);

            viewModel.ActiveQuizCategoryId   = quizCategory.Id;
            viewModel.ActiveQuizCategoryName = quizCategory.Name;
            viewModel.ActiveQuizCategoryIcon = quizCategory.FontAwesomeIconName;

            return(View(viewModel));
        }