public IActionResult Index(
            string?searchString         = null,
            string?existingFilterString = null,
            string?newFilterToAdd       = null,
            bool clearFilters           = false,
            int page         = 1,
            int?itemsPerPage = null
            )
        {
            existingFilterString = FilteringHelper.GetFilterString(
                existingFilterString,
                newFilterToAdd,
                clearFilters,
                Request,
                AdminFilterCookieName
                );

            var centreId           = User.GetCentreId();
            var adminUsersAtCentre = userDataService.GetAdminUsersByCentreId(centreId);
            var categories         = courseCategoriesDataService.GetCategoriesForCentreAndCentrallyManagedCourses(centreId);
            var loggedInUserId     = User.GetAdminId();
            var loggedInAdminUser  = userDataService.GetAdminUserById(loggedInUserId !.GetValueOrDefault());

            var availableFilters =
                AdministratorsViewModelFilterOptions.GetAllAdministratorsFilterModels(categories);

            var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions(
                new SearchOptions(searchString),
                new SortOptions(GenericSortingHelper.DefaultSortOption, GenericSortingHelper.Ascending),
                new FilterOptions(existingFilterString, availableFilters),
                new PaginationOptions(page, itemsPerPage)
                );

            var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate(
                adminUsersAtCentre,
                searchSortPaginationOptions
                );

            var model = new CentreAdministratorsViewModel(
                centreId,
                result,
                availableFilters,
                loggedInAdminUser !
                );

            Response.UpdateFilterCookie(AdminFilterCookieName, result.FilterString);

            return(View(model));
        }
Example #2
0
        public void Index_calls_expected_methods_and_returns_view()
        {
            // When
            var result = administratorController.Index();

            // Then
            using (new AssertionScope())
            {
                A.CallTo(() => userDataService.GetAdminUsersByCentreId(A <int> ._)).MustHaveHappened();
                A.CallTo(() => courseCategoriesDataService.GetCategoriesForCentreAndCentrallyManagedCourses(A <int> ._))
                .MustHaveHappened();
                A.CallTo(() => userDataService.GetAdminUserById(A <int> ._)).MustHaveHappened();
                A.CallTo(
                    () => searchSortFilterPaginateService.SearchFilterSortAndPaginate(
                        A <IEnumerable <AdminUser> > ._,
                        A <SearchSortFilterAndPaginateOptions> ._
                        )
                    ).MustHaveHappened();
                A.CallTo(
                    () => httpResponse.Cookies.Append(
                        CookieName,
                        A <string> ._,
                        A <CookieOptions> ._
                        )
                    )
                .MustHaveHappened();
                result.Should().BeViewResult().WithDefaultViewName();
            }
        }
Example #3
0
        public void Setup()
        {
            courseCategoriesDataService     = A.Fake <ICourseCategoriesDataService>();
            userDataService                 = A.Fake <IUserDataService>();
            centreContractAdminUsageService = A.Fake <ICentreContractAdminUsageService>();
            userService = A.Fake <IUserService>();

            A.CallTo(() => userDataService.GetAdminUsersByCentreId(A <int> ._)).Returns(adminUsers);
            A.CallTo(() => courseCategoriesDataService.GetCategoriesForCentreAndCentrallyManagedCourses(A <int> ._))
            .Returns(categories);

            httpRequest  = A.Fake <HttpRequest>();
            httpResponse = A.Fake <HttpResponse>();
            const string cookieName  = "AdminFilter";
            const string cookieValue = "Role|IsCentreAdmin|true";

            administratorController = new AdministratorController(
                userDataService,
                courseCategoriesDataService,
                centreContractAdminUsageService,
                userService
                )
                                      .WithMockHttpContext(httpRequest, cookieName, cookieValue, httpResponse)
                                      .WithMockUser(true)
                                      .WithMockServices()
                                      .WithMockTempData();
        }
Example #4
0
        public IActionResult EditAdminRoles(int adminId)
        {
            var centreId  = User.GetCentreId();
            var adminUser = userDataService.GetAdminUserById(adminId) !;

            var categories = courseCategoriesDataService.GetCategoriesForCentreAndCentrallyManagedCourses(centreId);

            categories = categories.Prepend(new Category {
                CategoryName = "All", CourseCategoryID = 0
            });
            var numberOfAdmins = centreContractAdminUsageService.GetCentreAdministratorNumbers(centreId);

            var model = new EditRolesViewModel(adminUser, centreId, categories, numberOfAdmins);

            return(View(model));
        }
Example #5
0
        public IActionResult Index(
            string?searchString  = null,
            string?sortBy        = null,
            string sortDirection = BaseSearchablePageViewModel.Ascending,
            string?filterBy      = null,
            string?filterValue   = null,
            int page             = 1
            )
        {
            sortBy ??= DefaultSortByOptions.Name.PropertyName;
            filterBy = FilteringHelper.GetFilterBy(
                filterBy,
                filterValue,
                Request,
                CourseFilterCookieName,
                CourseStatusFilterOptions.IsActive.FilterValue
                );

            var centreId      = User.GetCentreId();
            var categoryId    = User.GetAdminCourseCategoryFilter();
            var centreCourses =
                courseService.GetCentreSpecificCourseStatistics(centreId, categoryId);
            var categories = courseCategoriesDataService.GetCategoriesForCentreAndCentrallyManagedCourses(centreId)
                             .Select(c => c.CategoryName);
            var topics = courseTopicsDataService.GetCourseTopicsAvailableAtCentre(centreId).Select(c => c.CourseTopic);

            var model = new CourseSetupViewModel(
                centreCourses,
                categories,
                topics,
                searchString,
                sortBy,
                sortDirection,
                filterBy,
                page
                );

            Response.UpdateOrDeleteFilterCookie(CourseFilterCookieName, filterBy);

            return(View(model));
        }
Example #6
0
        public void GetCategoriesForCentreAndCentrallyManagedCourses_returns_expected_categories()
        {
            // Given
            const string categoryName = "Category";

            A.CallTo(() => courseCategoriesDataService.GetCategoriesForCentreAndCentrallyManagedCourses(CentreId))
            .Returns(new List <Category> {
                new Category {
                    CourseCategoryID = 1, CategoryName = categoryName
                }
            });

            // When
            var result = courseService.GetCategoriesForCentreAndCentrallyManagedCourses(CentreId);

            // Then
            result.Single().Should().Be(categoryName);
        }
Example #7
0
        public void Setup()
        {
            courseCategoryDataService = A.Fake <ICourseCategoriesDataService>();
            courseTopicsDataService   = A.Fake <ICourseTopicsDataService>();
            courseService             = A.Fake <ICourseService>();

            A.CallTo(() => courseService.GetCentreSpecificCourseStatistics(A <int> ._, A <int> ._)).Returns(courses);
            A.CallTo(() => courseCategoryDataService.GetCategoriesForCentreAndCentrallyManagedCourses(A <int> ._))
            .Returns(categories);
            A.CallTo(() => courseTopicsDataService.GetCourseTopicsAvailableAtCentre(A <int> ._)).Returns(topics);

            httpRequest  = A.Fake <HttpRequest>();
            httpResponse = A.Fake <HttpResponse>();
            const string cookieName  = "CourseFilter";
            const string cookieValue = "Status|Active|false";

            controller = new CourseSetupController(courseService, courseCategoryDataService, courseTopicsDataService)
                         .WithMockHttpContext(httpRequest, cookieName, cookieValue, httpResponse)
                         .WithMockUser(true)
                         .WithMockTempData();
        }
Example #8
0
        public IActionResult Index(int delegateId)
        {
            var centreId     = User.GetCentreId();
            var delegateUser = userDataService.GetDelegateUserCardById(delegateId) !;

            if (delegateUser.IsAdmin || !delegateUser.IsPasswordSet)
            {
                return(NotFound());
            }

            var categories = courseCategoriesDataService.GetCategoriesForCentreAndCentrallyManagedCourses(centreId);

            categories = categories.Prepend(new Category {
                CategoryName = "All", CourseCategoryID = 0
            });
            var numberOfAdmins = centreContractAdminUsageService.GetCentreAdministratorNumbers(centreId);

            var model = new PromoteToAdminViewModel(delegateUser, centreId, categories, numberOfAdmins);

            return(View(model));
        }