Пример #1
0
        /// <summary>
        /// Sets up the ViewBag to contain notification counts and collections such as messages, gifts received, and announcements.
        /// </summary>
        /// <returns></returns>
        protected async Task SetNotificationsAsync()
        {
            ViewBag.ShowNewTriviaText = false;
            ViewBag.ShowStoreSaleText = false;

            // notifications are only useful for logged in users
            if (User.Identity.IsAuthenticated)
            {
                string currentUserId = User.Identity.GetUserId();
                var    currentUser   = await UserManager.FindByIdAsync(currentUserId);

                ViewBag.MessageNotificationCount = await NotificationService.GetMessageNotificationCountAsync(currentUserId);

                ViewBag.PointsCount       = currentUser.CurrentPoints;
                ViewBag.NotificationCount = currentUser.NotificationCount;

                // are there any unplayed quizzes by the user
                // if so, show "New" on the trivia button
                int unfinishedQuizCount = await TriviaService.GetUnfinishedQuizCountForUserAsync(currentUserId);

                if (unfinishedQuizCount > 0)
                {
                    ViewBag.ShowNewTriviaText = true;
                }

                // are there any active sales
                // if so, show "Sale" on the store button
                bool isActiveSale = await StoreService.IsActiveSaleAsync();

                if (isActiveSale)
                {
                    ViewBag.ShowStoreSaleText = true;
                }
            }
        }