Ejemplo n.º 1
0
        private CompetencyResourceSignpostingViewModel PopulatedModel(int frameworkId, int?frameworkCompetencyGroupId = null, int?frameworkCompetencyId = null)
        {
            var model = new CompetencyResourceSignpostingViewModel(frameworkId, frameworkCompetencyId, frameworkCompetencyId);

            model.NameOfCompetency        = "I can organise my information and content using files and folders (either on my device, across multiple devices, or on the Cloud)";
            model.CompetencyResourceLinks = new List <SignpostingCardViewModel>()
            {
                new SignpostingCardViewModel()
                {
                    Id   = 1,
                    Name = "Cloud storage",
                    AssessmentQuestion = "Where are you now?",
                    MinimumResultMatch = 6,
                    MaximumResultMatch = 9,
                    CompareResultTo    = "Where do you need to be?"
                },
                new SignpostingCardViewModel()
                {
                    Id   = 2,
                    Name = "A guide to online file storage",
                    AssessmentQuestion = "Where are you now?",
                    MinimumResultMatch = 1,
                    MaximumResultMatch = 10,
                    CompareResultTo    = "Where do you need to be?"
                },
            };
            return(model);
        }
        private BulkResourceReferences GetBulkResourcesByReferenceIds(CompetencyResourceSignpostingViewModel model, IEnumerable <CompetencyResourceAssessmentQuestionParameter> parameters)
        {
            var resourceRefIds = parameters.Select(p => p.ResourceRefId);

            try
            {
                return(this.learningHubApiClient.GetBulkResourcesByReferenceIds(resourceRefIds).Result);
            }
            catch
            {
                model.LearningHubApiError = true;
                return(null);
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> SearchLearningResourcesAsync(int frameworkId, int frameworkCompetencyId, int?frameworkCompetencyGroupId, string searchText, int page = 1)
        {
            var response = new CompetencyResourceSignpostingViewModel(frameworkId, frameworkCompetencyId, frameworkCompetencyGroupId);

            if (frameworkCompetencyGroupId.HasValue)
            {
                var competency = frameworkService.GetCompetencyGroupBaseById(frameworkCompetencyGroupId.Value);
                response.NameOfCompetency = competency?.Name ?? "";
            }
            if (searchText?.Trim().Length > 1)
            {
                response.Page       = page;
                response.SearchText = searchText;
                await GetResourcesFromLearningHubApiAsync(response);
            }
            return(View("Developer/AddCompetencyLearningResources", response));
        }
        private CompetencyResourceSignpostingViewModel GetSignpostingResourceParameters(int frameworkId, int frameworkCompetencyId)
        {
            var frameworkCompetency = frameworkService.GetFrameworkCompetencyById(frameworkCompetencyId);
            var parameters          = frameworkService.GetSignpostingResourceParametersByFrameworkAndCompetencyId(frameworkId, frameworkCompetency.CompetencyID);
            var model = new CompetencyResourceSignpostingViewModel(frameworkId, frameworkCompetencyId, frameworkCompetencyId)
            {
                NameOfCompetency = frameworkCompetency.Name,
            };
            var learningHubApiReferences       = GetBulkResourcesByReferenceIds(model, parameters);
            var learningHubApiResourcesByRefId = learningHubApiReferences?.ResourceReferences?.ToDictionary(k => k.RefId, v => v);

            model.CompetencyResourceLinks = (
                from p in parameters
                let resource = !model.LearningHubApiError && learningHubApiResourcesByRefId.Keys.Contains(p.ResourceRefId) ? learningHubApiResourcesByRefId[p.ResourceRefId] : null
                               select new SignpostingCardViewModel()
            {
                AssessmentQuestionId = p.AssessmentQuestionId,
                CompetencyLearningResourceId = p.CompetencyLearningResourceId,
                Name = resource?.Title ?? p.OriginalResourceName,
                AssessmentQuestion = p.Question,
                AssessmentQuestionLevelDescriptors = p.AssessmentQuestionId.HasValue && p.AssessmentQuestionInputTypeId != 2 ?
                                                     frameworkService.GetLevelDescriptorsForAssessmentQuestionId(
                    p.AssessmentQuestionId.Value,
                    GetAdminId(),
                    p.AssessmentQuestionMinValue,
                    p.AssessmentQuestionMaxValue,
                    p.AssessmentQuestionMinValue == 0).ToList()
                            : null,
                LevelDescriptorsAreZeroBased = p.AssessmentQuestionMinValue == 0,
                AssessmentQuestionInputTypeId = p.AssessmentQuestionInputTypeId,
                MinimumResultMatch = p.MinResultMatch,
                MaximumResultMatch = p.MaxResultMatch,
                CompareResultTo = p.CompareResultTo,
                Essential = p.Essential,
                ParameterHasNotBeenSet = p.IsNew,
                Description = resource?.Description,
                Catalogue = resource?.Catalogue?.Name,
                ResourceType = DisplayStringHelper.AddSpacesToPascalCaseString(resource?.ResourceType ?? p.OriginalResourceType),
                ResourceRefId = resource?.RefId ?? p.ResourceRefId,
                Rating = resource?.Rating ?? p.OriginalRating,
                UnmatchedResource = learningHubApiReferences?.UnmatchedResourceReferenceIds?.Contains(p.ResourceRefId) ?? false
            }).ToList();
            return(model);
        }
        public async Task <IActionResult> SearchLearningResourcesAsync(int frameworkId, int frameworkCompetencyId, int?frameworkCompetencyGroupId, int?catalogueId, string searchText, int page)
        {
            var model = new CompetencyResourceSignpostingViewModel(frameworkId, frameworkCompetencyId, frameworkCompetencyGroupId);

            Catalogues = Catalogues ?? (await this.learningHubApiClient.GetCatalogues())?.Catalogues?.OrderBy(c => c.Name).ToList();
            if (catalogueId.HasValue)
            {
                Response.Cookies.SetSignpostingCookie(new { CatalogueId = catalogueId });
            }
            else
            {
                catalogueId = Request.Cookies.RetrieveSignpostingFromCookie()?.CatalogueId ?? 0;
            }

            model.CatalogueId = catalogueId;
            model.Catalogues  = Catalogues;
            model.Page        = Math.Max(page, 1);

            if (frameworkCompetencyGroupId.HasValue)
            {
                var competency = frameworkService.GetFrameworkCompetencyById(frameworkCompetencyId);
                model.NameOfCompetency = competency?.Name ?? "";
            }
            if (searchText?.Trim().Length > 1)
            {
                model.SearchText = searchText;
                try
                {
                    var offset = (int?)((model.Page - 1) * CompetencyResourceSignpostingViewModel.ItemsPerPage);
                    model.SearchResult = await this.learningHubApiClient.SearchResource(
                        model.SearchText ?? String.Empty,
                        catalogueId > 0?catalogueId : null,
                        offset,
                        CompetencyResourceSignpostingViewModel.ItemsPerPage);

                    model.LearningHubApiError = model.SearchResult == null;
                }
                catch (Exception)
                {
                    model.LearningHubApiError = true;
                }
            }
            return(View("Developer/AddCompetencyLearningResources", model));
        }
Ejemplo n.º 6
0
        private async Task GetResourcesFromLearningHubApiAsync(CompetencyResourceSignpostingViewModel model)
        {
            try
            {
                var httpClient      = new HttpClient();
                var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
                var configuration   = SignpostingConfiguration ?? (new ConfigurationBuilder()
                                                                   .SetBasePath(Directory.GetCurrentDirectory())
                                                                   .AddJsonFile("appsettings.Development.json")
                                                                   .AddUserSecrets(typeof(Program).Assembly, true)
                                                                   .AddEnvironmentVariables(environmentName)
                                                                   .Build());
                var apiClient = new LearningHubApiClient(httpClient, configuration);
                var offset    = (int?)((model.Page - 1) * CompetencyResourceSignpostingViewModel.ItemsPerPage);
                model.SearchResult = await apiClient.SearchResource(model.SearchText ?? String.Empty, offset, CompetencyResourceSignpostingViewModel.ItemsPerPage);

                model.LearningHubApiError = model.SearchResult == null;
                SignpostingConfiguration  = configuration;
            }
            catch (Exception)
            {
                model.LearningHubApiError = true;
            }
        }