Example #1
0
            public async Task <ViewModel> Handle(Query request, CancellationToken cancellationToken)
            {
                var viewModel = new ViewModel();

                viewModel.ValidationResult = await queryValidator.ValidateAsync(request, cancellationToken);

                if (!viewModel.ValidationResult.IsValid)
                {
                    return(viewModel);
                }

                var certificate = await privateCertRepository.GetCertificateAsync(request.CertificateId);

                var passphrase = await privateCertRepository.GetPassphraseAsync();

                var passphraseDecrypted = StringCipher.Decrypt(passphrase, request.MasterKeyDecrypted);

                var x509 = new X509Certificate2();

                x509.Import(certificate.PfxData, passphraseDecrypted, X509KeyStorageFlags.Exportable);
                viewModel.CertificateData    = x509.Export(certificate.CertificateType == CertificateTypeEnum.Root ? X509ContentType.Cert : X509ContentType.Pfx, string.Empty);
                viewModel.Extension          = (certificate.CertificateType == CertificateTypeEnum.Root ? ".cer" : ".pfx");
                viewModel.ExtensionFilter    = (certificate.CertificateType == CertificateTypeEnum.Root ? "Security Certificate (.cer)|*.cer" : "PKCS #12 Certificate (.pfx)|*.pfx");
                viewModel.FileNameSuggestion = certificate.Name.Replace("*", "_") + viewModel.Extension;

                return(viewModel);
            }
        public async Task <QueryResponse> Handle(SearchQuery request, CancellationToken cancellationToken)
        {
            var validator        = new QueryValidator();
            var validationResult = await validator.ValidateAsync(request);

            if (!validationResult.IsValid)
            {
                var vm = request.Adapt <ViewModel>();
                return(new ModelWithErrors <ViewModel>(vm, validationResult));
            }

            var searchResults = await _standardsAndFrameworksCache.SearchStandards(request.Search);

            return(new ViewModel()
            {
                Search = request.Search,
                SearchWasDone = true,
                Results = searchResults
                          .Select(s => new ViewModelResult()
                {
                    ApprenticeshipTitle = s.StandardName,
                    NotionalNVQLevelv2 = s.NotionalNVQLevelv2,
                    OtherBodyApprovalRequired = s.OtherBodyApprovalRequired,
                    StandardCode = s.StandardCode,
                    StandardVersion = s.Version
                })
                          .ToList()
            });
        }
Example #3
0
            public async Task <ViewModel> Handle(Query request, CancellationToken cancellationToken)
            {
                var viewModel = new ViewModel();

                viewModel.ValidationResult = await queryValidator.ValidateAsync(request, cancellationToken);

                if (!viewModel.ValidationResult.IsValid)
                {
                    return(viewModel);
                }

                var certificates = await privateCertRepository.GetAllCertificatesAsync();

                viewModel.Certificates = AutoMapper.Mapper.Map <ICollection <CertificateVM> >(certificates);

                return(viewModel);
            }
Example #4
0
            public async Task <ViewModel> Handle(Query request, CancellationToken cancellationToken)
            {
                var viewModel = new ViewModel();

                viewModel.ValidationResult = await queryValidator.ValidateAsync(request, cancellationToken);

                if (!viewModel.ValidationResult.IsValid)
                {
                    return(viewModel);
                }

                viewModel.AuthorityCertificates = await privateCertRepository.GetValidAuthorityCertificatesAsync();

                viewModel.SelectedAuthorityCertificateId = viewModel.AuthorityCertificates.First().CertificateId;
                viewModel.ExpirationDateInDays           = 720;
                viewModel.SubjectName = "some.domain.com or *.domain.com";

                return(viewModel);
            }
Example #5
0
        public async Task <QueryResponse> Handle(SearchQuery request, CancellationToken cancellationToken)
        {
            var validator        = new QueryValidator();
            var validationResult = await validator.ValidateAsync(request);

            if (!validationResult.IsValid)
            {
                var vm = request.Adapt <ViewModel>();
                return(new ModelWithErrors <ViewModel>(vm, validationResult));
            }

            var results = await Task.WhenAll(
                // There's not currently support for multi-select faceted search, so we need to get all the results for the search term before filtering on facets.
                _searchClient.Search(new LarsSearchQuery
            {
                SearchText = request.SearchTerm,
                CertificationEndDateFilter = DateTimeOffset.UtcNow,
                Facets   = new[] { nameof(Lars.AwardOrgCode), nameof(Lars.NotionalNVQLevelv2) },
                PageSize = 0
            }),
                _searchClient.Search(new LarsSearchQuery
            {
                SearchText = request.SearchTerm,
                CertificationEndDateFilter = DateTimeOffset.UtcNow,
                Facets     = new[] { nameof(Lars.AwardOrgCode), nameof(Lars.NotionalNVQLevelv2) },
                PageSize   = _larsSearchSettings.ItemsPerPage,
                PageNumber = request.PageNumber,
                NotionalNVQLevelv2Filters = request.NotionalNVQLevelv2,
                AwardOrgCodeFilters       = request.AwardingOrganisation,
                //AwardOrgAimRefFilters = request.AwardOrgAimRefFilter,
            }));

            var unfilteredResult = results[0];
            var result           = results[1];

            var res = result.Items.Select(x => new Result()
            {
                CourseName           = x.Record.LearnAimRefTitle,
                LARSCode             = x.Record.LearnAimRef,
                Level                = x.Record.NotionalNVQLevelv2,
                AwardingOrganisation = x.Record.AwardOrgName,
                OperationalEndDate   = x.Record.OperationalEndDate.HasValue ? x.Record.OperationalEndDate.Value.ToString("dd MMM yyyy") : string.Empty,
                EffectiveTo          = x.Record.EffectiveTo.HasValue ? x.Record.EffectiveTo.Value.ToString("dd MMM yyyy") : string.Empty,
            }).OrderBy(x => x.CourseName);

            var vmodel = new ViewModel()
            {
                SearchWasDone             = true,
                PageNumber                = request.PageNumber ?? 1,
                Total                     = result.TotalCount,
                SearchResults             = res.ToList(),
                PageSize                  = _larsSearchSettings.ItemsPerPage,
                SearchTerm                = request.SearchTerm,
                TotalPages                = result.TotalCount.HasValue ? (int)Math.Ceiling((decimal)result.TotalCount / _larsSearchSettings.ItemsPerPage) : 0,
                NotionalNVQLevelv2        = request.NotionalNVQLevelv2,
                AwardingOrganisation      = request.AwardingOrganisation,
                ProviderId                = request.ProviderId,
                NotionalNVQLevelv2Filters = new[]
                {
                    new LarsSearchFilterModel
                    {
                        Title = "Qualification level",
                        Items = unfilteredResult.Facets[nameof(Lars.NotionalNVQLevelv2)]
                                .Select((f, i) =>
                                        new LarsSearchFilterItemModel
                        {
                            Id         = $"nvqlevel2-{i}",
                            Name       = $"nvqlevel2-{i}",
                            Text       = LarsSearchFilterItemModel.FormatAwardOrgCodeSearchFilterItemText(f.Key.ToString()),
                            Value      = f.Key.ToString(),
                            Count      = (int)(f.Value ?? 0),
                            IsSelected = request.NotionalNVQLevelv2 != null ? request.NotionalNVQLevelv2.Contains(f.Key.ToString()) : false
                        })
                                .OrderBy(f => f.Text).ToArray()
                    }
                },
                AwardingOrganisationFilters = new[]
                {
                    new LarsSearchFilterModel
                    {
                        Title = "Awarding organisation",
                        Items = unfilteredResult.Facets[nameof(Lars.AwardOrgCode)]
                                .Select((f, i) =>
                                        new LarsSearchFilterItemModel
                        {
                            Id         = $"awardcode-{i}",
                            Name       = $"awardcode-{i}",
                            Text       = f.Key.ToString(),
                            Value      = f.Key.ToString(),
                            Count      = (int)(f.Value ?? 0),
                            IsSelected = request.AwardingOrganisation != null ? request.AwardingOrganisation.Contains(f.Key.ToString()) : false
                        })
                                .OrderBy(f => f.Text).ToArray()
                    }
                },
            };

            return(vmodel);
        }
Example #6
0
 public async Task <ValidationResult> Handle(Query request, CancellationToken cancellationToken)
 {
     return(await queryValidator.ValidateAsync(request, cancellationToken));
 }