コード例 #1
0
        public void Index_sets_cookie_when_unacknowledged_notifications_exist()
        {
            // Given
            var testDate = new DateTime(2021, 8, 23);

            A.CallTo(() => clockService.UtcNow).Returns(testDate);
            var expectedExpiry = testDate.AddHours(24);

            A.CallTo(() => systemNotificationsDataService.GetUnacknowledgedSystemNotifications(A <int> ._))
            .Returns(new List <SystemNotification> {
                SystemNotificationTestHelper.GetDefaultSystemNotification()
            });

            // When
            var result = controller.Index();

            // Then
            using (new AssertionScope())
            {
                result.Should().BeViewResult().WithDefaultViewName();
                A.CallTo(
                    () => httpResponse.Cookies.Append(
                        SystemNotificationCookieHelper.CookieName,
                        "7",
                        A <CookieOptions> .That.Matches(co => co.Expires == expectedExpiry)
                        )
                    ).MustHaveHappened();
            }
        }
コード例 #2
0
        public void Index_redirects_to_Notifications_page_when_unacknowledged_notifications_have_not_been_skipped()
        {
            // Given
            A.CallTo(() => systemNotificationsDataService.GetUnacknowledgedSystemNotifications(A <int> ._))
            .Returns(new List <SystemNotification> {
                SystemNotificationTestHelper.GetDefaultSystemNotification()
            });

            // When
            var result = dashboardController.Index();

            // Then
            result.Should().BeRedirectToActionResult().WithControllerName("SystemNotifications")
            .WithActionName("Index");
        }
コード例 #3
0
        public IActionResult Index(int page = 1)
        {
            var adminId = User.GetAdminId() !.Value;
            var unacknowledgedNotifications =
                systemNotificationsDataService.GetUnacknowledgedSystemNotifications(adminId).ToList();

            if (unacknowledgedNotifications.Count > 0)
            {
                Response.Cookies.SetSkipSystemNotificationCookie(adminId, clockService.UtcNow);
            }
            else if (Request.Cookies.HasSkippedNotificationsCookie(adminId))
            {
                Response.Cookies.DeleteSkipSystemNotificationCookie();
            }

            const int numberOfNotificationsPerPage = 1;
            var       searchSortPaginationOptions  = new SearchSortFilterAndPaginateOptions(
                null,
                null,
                null,
                new PaginationOptions(page, numberOfNotificationsPerPage)
                );
            var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate(
                unacknowledgedNotifications,
                searchSortPaginationOptions
                );

            var model = new SystemNotificationsViewModel(result);

            return(View(model));
        }
コード例 #4
0
        public IActionResult Index()
        {
            var adminId = User.GetAdminId() !.Value;
            var unacknowledgedNotifications =
                systemNotificationsDataService.GetUnacknowledgedSystemNotifications(adminId).ToList();

            if (!Request.Cookies.HasSkippedNotificationsCookie(adminId) && unacknowledgedNotifications.Any())
            {
                return(RedirectToAction("Index", "SystemNotifications"));
            }

            var centreId = User.GetCentreId();

            var dashboardInformation = dashboardInformationService.GetDashboardInformationForCentre(centreId, adminId);

            if (dashboardInformation == null)
            {
                return(NotFound());
            }

            var model = new CentreDashboardViewModel(
                dashboardInformation,
                Request.GetUserIpAddressFromRequest(),
                unacknowledgedNotifications.Count
                );

            return(View(model));
        }
コード例 #5
0
        public IActionResult Index(int page = 1)
        {
            var adminId = User.GetAdminId() !.Value;
            var unacknowledgedNotifications =
                systemNotificationsDataService.GetUnacknowledgedSystemNotifications(adminId).ToList();

            if (unacknowledgedNotifications.Count > 0)
            {
                Response.Cookies.SetSkipSystemNotificationCookie(adminId, clockService.UtcNow);
            }
            else if (Request.Cookies.HasSkippedNotificationsCookie(adminId))
            {
                Response.Cookies.DeleteSkipSystemNotificationCookie();
            }

            var model = new SystemNotificationsViewModel(unacknowledgedNotifications, page);

            return(View(model));
        }
コード例 #6
0
        public IActionResult Index()
        {
            var adminId = User.GetAdminId() !.Value;
            var unacknowledgedNotifications =
                systemNotificationsDataService.GetUnacknowledgedSystemNotifications(adminId).ToList();

            if (!Request.Cookies.HasSkippedNotificationsCookie(adminId) && unacknowledgedNotifications.Any())
            {
                return(RedirectToAction("Index", "SystemNotifications"));
            }

            var adminUser     = userDataService.GetAdminUserById(adminId) !;
            var centreId      = User.GetCentreId();
            var centre        = centresDataService.GetCentreDetailsById(centreId) !;
            var delegateCount = userDataService.GetNumberOfApprovedDelegatesAtCentre(centreId);
            var courseCount   =
                courseDataService.GetNumberOfActiveCoursesAtCentreFilteredByCategory(
                    centreId,
                    adminUser.CategoryIdFilter
                    );
            var adminCount         = userDataService.GetNumberOfActiveAdminsAtCentre(centreId);
            var supportTicketCount = ticketDataService.GetNumberOfUnarchivedTicketsForCentreId(centreId);
            var centreRank         = centresService.GetCentreRankForCentre(centreId);

            var model = new CentreDashboardViewModel(
                centre,
                adminUser.FirstName,
                adminUser.CategoryName,
                Request.GetUserIpAddressFromRequest(),
                delegateCount,
                courseCount,
                adminCount,
                supportTicketCount,
                centreRank,
                unacknowledgedNotifications.Count
                );

            return(View(model));
        }