public IActionResult Index(int customisationId)
        {
            TempData.Clear();
            var courseAdminFields = courseAdminFieldsService.GetCourseAdminFieldsForCourse(customisationId);

            var model = new AdminFieldsViewModel(courseAdminFields.AdminFields, customisationId);

            return(View(model));
        }
        public void GetCoursesAndCourseDelegatesForCentre_populates_course_delegates_data()
        {
            // Given
            const int centreId           = 2;
            const int categoryId         = 1;
            const int customisationId    = 1;
            var       delegateCourseInfo = new DelegateCourseInfo();

            A.CallTo(() => courseDataService.GetCoursesAvailableToCentreByCategory(centreId, categoryId))
            .Returns(
                new List <CourseAssessmentDetails>
            {
                new CourseAssessmentDetails {
                    CustomisationId = customisationId
                }
            }
                );
            A.CallTo(() => courseDataService.GetDelegateCourseInfosForCourse(A <int> ._, A <int> ._))
            .Returns(new List <DelegateCourseInfo> {
                delegateCourseInfo
            });
            A.CallTo(() => courseAdminFieldsService.GetCourseAdminFieldsForCourse(A <int> ._))
            .Returns(
                new CourseAdminFields(
                    customisationId,
                    new List <CourseAdminField> {
                new CourseAdminField(1, "prompt", null)
            }
                    )
                );
            A.CallTo(() => courseAdminFieldsService.GetCourseAdminFieldsWithAnswersForCourse(delegateCourseInfo))
            .Returns(
                new List <CourseAdminFieldWithAnswer>
            {
                new CourseAdminFieldWithAnswer(1, "prompt", null, "answer")
            }
                );

            // When
            var result = courseDelegatesService.GetCoursesAndCourseDelegatesForCentre(
                centreId,
                categoryId,
                null
                );

            // Then
            using (new AssertionScope())
            {
                result.Courses.Should().HaveCount(1);
                result.Delegates.Should().HaveCount(1);
                result.Delegates.First().CourseAdminFields.Should().HaveCount(1);
                result.CustomisationId.Should().Be(customisationId);
                result.CourseAdminFields.Should().HaveCount(1);
            }
        }
        public IActionResult AllCourseDelegates(int customisationId)
        {
            var centreId        = User.GetCentreId();
            var courseDelegates = courseDelegatesService.GetCourseDelegatesForCentre(customisationId, centreId);
            var adminFields     = courseAdminFieldsService.GetCourseAdminFieldsForCourse(customisationId);
            var model           = new AllCourseDelegatesViewModel(courseDelegates, adminFields.AdminFields);

            return(View(model));
        }
        private void PopulateCourseDelegatesSheetForCourse(
            IXLWorkbook workbook,
            int customisationId,
            int centreId,
            string?sortBy,
            string?filterString,
            string sortDirection
            )
        {
            var adminFields = courseAdminFieldsService.GetCourseAdminFieldsForCourse(customisationId);

            var customRegistrationPrompts = registrationPromptsService.GetCentreRegistrationPromptsByCentreId(centreId);

            var courseDelegates = courseDataService.GetDelegatesOnCourseForExport(customisationId, centreId)
                                  .ToList();

            var filteredCourseDelegates =
                FilteringHelper.FilterItems(courseDelegates.AsQueryable(), filterString).ToList();
            var sortedCourseDelegates =
                GenericSortingHelper.SortAllItems(
                    filteredCourseDelegates.AsQueryable(),
                    sortBy ?? nameof(CourseDelegateForExport.FullNameForSearchingSorting),
                    sortDirection
                    );

            var dataTable = new DataTable();

            SetUpDataTableColumns(customRegistrationPrompts, adminFields, dataTable);

            foreach (var courseDelegate in sortedCourseDelegates)
            {
                AddDelegateToDataTable(dataTable, courseDelegate, customRegistrationPrompts, adminFields);
            }

            if (dataTable.Rows.Count == 0)
            {
                var row = dataTable.NewRow();
                dataTable.Rows.Add(row);
            }

            ClosedXmlHelper.AddSheetToWorkbook(
                workbook,
                $"Course {customisationId}",
                dataTable.AsEnumerable(),
                XLTableTheme.None
                );

            FormatWorksheetColumns(workbook, dataTable);
        }
        EditDelegateCourseAdminField_GET_returns_not_found_if_no_course_admin_field_corresponds_to_prompt_number()
        {
            // Given
            const int    validPromptNumber   = 1;
            const int    invalidPromptNumber = 2;
            const string promptText          = "Prompt text";
            const string options             = "Answer";

            var courseAdminFieldWithAnswer = new CourseAdminFieldWithAnswer(
                validPromptNumber,
                promptText,
                options,
                options
                );
            var delegateCourseInfo = new DelegateCourseInfo
            {
                CourseAdminFields = new List <CourseAdminFieldWithAnswer> {
                    courseAdminFieldWithAnswer
                }
            };
            var delegateCourseDetails = new DetailedCourseProgress(
                new Progress(),
                new List <DetailedSectionProgress>(),
                delegateCourseInfo
                );

            var courseAdminField           = new CourseAdminField(validPromptNumber, promptText, options);
            var courseAdminFieldsForCourse = new CourseAdminFields(
                CustomisationId,
                new List <CourseAdminField> {
                courseAdminField
            }
                );

            A.CallTo(() => progressService.GetDetailedCourseProgress(ProgressId))
            .Returns(delegateCourseDetails);
            A.CallTo(() => courseAdminFieldsService.GetCourseAdminFieldsForCourse(CustomisationId))
            .Returns(courseAdminFieldsForCourse);

            // When
            var result = delegateProgressController.EditDelegateCourseAdminField(
                invalidPromptNumber,
                ProgressId,
                DelegateAccessRoute.CourseDelegates
                );

            // Then
            result.Should().BeNotFoundResult();
        }
Exemplo n.º 6
0
        public void GetDelegateDownloadFileForCourse_returns_expected_excel_data()
        {
            // Given
            const int customisationId = 1;
            const int centreId        = 1;

            using var expectedWorkbook = new XLWorkbook(
                      TestContext.CurrentContext.TestDirectory + CourseDelegateExportCurrentDataDownloadRelativeFilePath
                      );

            A.CallTo(() => courseDataService.GetDelegatesOnCourseForExport(customisationId, centreId))
            .Returns(courseDelegates.Where(c => c.ApplicationName == "Course One"));

            var centreRegistrationPrompts = new List <CentreRegistrationPrompt>
            {
                new CentreRegistrationPrompt(1, 1, "Role type", null, true),
                new CentreRegistrationPrompt(2, 2, "Manager", null, true),
                new CentreRegistrationPrompt(3, 3, "Base / office / place of work", null, true),
                new CentreRegistrationPrompt(4, 4, "Base / office / place of work", null, true),
                new CentreRegistrationPrompt(5, 5, "Contact telephone number", null, true),
            };

            A.CallTo(() => registrationPromptsService.GetCentreRegistrationPromptsByCentreId(centreId))
            .Returns(new CentreRegistrationPrompts(centreId, centreRegistrationPrompts));

            var adminFields = new List <CourseAdminField>
            {
                new CourseAdminField(1, "Access Permissions", null),
            };

            A.CallTo(() => courseAdminFieldsService.GetCourseAdminFieldsForCourse(customisationId))
            .Returns(new CourseAdminFields(customisationId, adminFields));

            // When
            var resultBytes = courseDelegatesDownloadFileService.GetCourseDelegateDownloadFileForCourse(
                customisationId,
                centreId,
                null,
                null
                );

            using var resultsStream  = new MemoryStream(resultBytes);
            using var resultWorkbook = new XLWorkbook(resultsStream);

            // Then
            SpreadsheetTestHelper.AssertSpreadsheetsAreEquivalent(expectedWorkbook, resultWorkbook);
        }
        public void GetCourseAdminFieldsForCourse_Returns_Populated_CourseAdminFields()
        {
            // Given
            var expectedPrompt1 =
                PromptsTestHelper.GetDefaultCourseAdminField(1, "System Access Granted", "Test");
            var expectedPrompt2   = PromptsTestHelper.GetDefaultCourseAdminField(2, "Priority Access");
            var courseAdminFields = new List <CourseAdminField> {
                expectedPrompt1, expectedPrompt2
            };
            var expectedCourseAdminFields = PromptsTestHelper.GetDefaultCourseAdminFields(courseAdminFields);

            A.CallTo(() => courseAdminFieldsDataService.GetCourseAdminFields(100))
            .Returns(PromptsTestHelper.GetDefaultCourseAdminFieldsResult());

            // When
            var result = courseAdminFieldsService.GetCourseAdminFieldsForCourse(100);

            // Then
            result.Should().BeEquivalentTo(expectedCourseAdminFields);
        }
        public void AdminFields_returns_AdminFields_page_when_appropriate_course_found_and_clears_TempData()
        {
            // Given
            var courseAdminField1 =
                PromptsTestHelper.GetDefaultCourseAdminField(1, "System Access Granted", "Yes\r\nNo");
            var courseAdminFields = new List <CourseAdminField> {
                courseAdminField1
            };

            A.CallTo(() => courseAdminFieldsService.GetCourseAdminFieldsForCourse(A <int> ._))
            .Returns(PromptsTestHelper.GetDefaultCourseAdminFields(courseAdminFields));
            controller.TempData.Set(courseAdminField1);

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

            // Then
            controller.TempData.Peek <CourseAdminField>().Should().BeNull();
            result.Should().BeViewResult().WithDefaultViewName().ModelAs <AdminFieldsViewModel>();
        }
Exemplo n.º 9
0
        public CourseDelegatesData GetCoursesAndCourseDelegatesForCentre(
            int centreId,
            int?categoryId,
            int?customisationId
            )
        {
            var courses = courseDataService.GetCoursesAvailableToCentreByCategory(centreId, categoryId).ToList();

            if (customisationId != null && courses.All(c => c.CustomisationId != customisationId))
            {
                var exceptionMessage =
                    $"No course with customisationId {customisationId} available at centre {centreId} within " +
                    $"{(categoryId.HasValue ? $"category {categoryId}" : "any category")}";
                throw new CourseAccessDeniedException(exceptionMessage);
            }

            var activeCoursesAlphabetical   = courses.Where(c => c.Active).OrderBy(c => c.CourseName);
            var inactiveCoursesAlphabetical =
                courses.Where(c => !c.Active).OrderBy(c => c.CourseName);

            var orderedCourses = activeCoursesAlphabetical.Concat(inactiveCoursesAlphabetical).ToList();

            var currentCustomisationId = customisationId ?? orderedCourses.FirstOrDefault()?.CustomisationId;

            var courseDelegates = currentCustomisationId.HasValue
                ? GetCourseDelegatesForCentre(currentCustomisationId.Value, centreId)
                : new List <CourseDelegate>();

            var courseAdminFields = currentCustomisationId.HasValue
                ? courseAdminFieldsService.GetCourseAdminFieldsForCourse(currentCustomisationId.Value).AdminFields
                : new List <CourseAdminField>();

            return(new CourseDelegatesData(
                       currentCustomisationId,
                       orderedCourses,
                       courseDelegates,
                       courseAdminFields
                       ));
        }