public async Task <ActionResult> Index() { var currentUserId = User.Identity.GetUserId(); TriviaDashboardViewModel viewModel = new TriviaDashboardViewModel(); viewModel.NewQuizzes = await TriviaService.GetNewQuizzesAsync(); viewModel.DailyQuizzes = await TriviaService.GetDailyQuizzesAsync(5); viewModel.TrendingQuizzes = await GetTrendingQuizzesAsync(); viewModel.PopularQuizzes = await GetPopularQuizzesAsync(); // unauthenticated users don't have any quizzes to track if (User.Identity.IsAuthenticated) { viewModel.UnfinishedQuizzes = await TriviaService.GetUnfinishedQuizzesAsync(User.Identity.GetUserId()); } // alters the viewmodel's list of quizzes to indicate if the quiz has already been completed by the currently logged in user await SetQuizzesCompletedByCurrentUser(currentUserId, viewModel); viewModel.RecentlyCompletedQuizzes = await TriviaService.GetUsersCompletedQuizzesAsync(currentUserId); viewModel.QuizCategories = await TriviaService.GetQuizCategoriesAsync(); await SetNotificationsAsync(); return(View(viewModel)); }
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)); }
public async Task <ActionResult> Top() { await SetNotificationsAsync(); var currentUserId = User.Identity.GetUserId(); TriviaTopPlayersViewModel viewModel = new TriviaTopPlayersViewModel(); var topPlayers = await TriviaService.GetTopPlayersAsync(); viewModel.Players = Mapper.Map <IReadOnlyCollection <Models.Profile>, IReadOnlyCollection <ProfileViewModel> >(topPlayers); viewModel.QuizCategories = await TriviaService.GetQuizCategoriesAsync(); viewModel.TrendingQuizzes = await GetTrendingQuizzesAsync(); viewModel.PopularQuizzes = await GetPopularQuizzesAsync(); viewModel.RecentlyCompletedQuizzes = await TriviaService.GetUsersCompletedQuizzesAsync(currentUserId); return(View(viewModel)); }