public async Task <FlowModel> Initialize(Guid providerId)
        {
            var model = new FlowModel();

            var provider = await _cosmosDbQueryDispatcher.ExecuteQuery(
                new Core.DataStore.CosmosDb.Queries.GetProviderById()
            {
                ProviderId = providerId
            });

            if (!string.IsNullOrEmpty(provider.MarketingInformation))
            {
                model.SetProviderDetails(Html.SanitizeHtml(provider.MarketingInformation));
            }

            var submission = await _sqlDbQueryDispatcher.ExecuteQuery(new GetLatestApprenticeshipQASubmissionForProvider()
            {
                ProviderId = providerId
            });

            if (!(submission.Value is None))
            {
                var apprenticeshipId = submission.AsT1.Apprenticeships.First().ApprenticeshipId;
                var apprenticeship   = (await _cosmosDbQueryDispatcher.ExecuteQuery(
                                            new GetApprenticeshipsByIds()
                {
                    ApprenticeshipIds = new Guid[] { apprenticeshipId }
                }))[apprenticeshipId];

                StandardOrFramework standardOrFramework;

                if (apprenticeship.StandardCode.HasValue)
                {
                    var standard = await _standardsAndFrameworksCache.GetStandard(
                        apprenticeship.StandardCode.Value,
                        apprenticeship.Version.Value);

                    standardOrFramework = new StandardOrFramework(
                        new Standard()
                    {
                        StandardCode              = apprenticeship.StandardCode.Value,
                        CosmosId                  = apprenticeship.StandardId.Value,
                        Version                   = standard.Version,
                        StandardName              = standard.StandardName,
                        NotionalNVQLevelv2        = apprenticeship.NotionalNVQLevelv2,
                        OtherBodyApprovalRequired = standard.OtherBodyApprovalRequired
                    });
                }
                else  // apprenticeship.FrameworkCode.HasValue
                {
                    var framework = await _standardsAndFrameworksCache.GetFramework(
                        apprenticeship.FrameworkCode.Value,
                        apprenticeship.ProgType.Value,
                        apprenticeship.PathwayCode.Value);

                    standardOrFramework = new StandardOrFramework(
                        new Framework()
                    {
                        FrameworkCode = apprenticeship.FrameworkCode.Value,
                        CosmosId      = apprenticeship.FrameworkId.Value,
                        ProgType      = apprenticeship.ProgType.Value,
                        PathwayCode   = apprenticeship.PathwayCode.Value,
                        NasTitle      = framework.NasTitle
                    });
                }

                model.SetApprenticeshipStandardOrFramework(standardOrFramework);

                model.SetApprenticeshipId(apprenticeship.Id);

                model.SetApprenticeshipDetails(
                    apprenticeship.MarketingInformation,
                    apprenticeship.Url,
                    apprenticeship.ContactTelephone,
                    apprenticeship.ContactEmail,
                    apprenticeship.ContactWebsite);

                model.SetApprenticeshipLocationType(
                    ((apprenticeship.ApprenticeshipLocations.Any(l => l.VenueId.HasValue) ? ApprenticeshipLocationType.ClassroomBased : 0) |
                     (apprenticeship.ApprenticeshipLocations.Any(l => l.National == true || (l.Regions?.Count() ?? 0) > 0) ? ApprenticeshipLocationType.EmployerBased : 0)));

                if (model.ApprenticeshipLocationType.Value.HasFlag(ApprenticeshipLocationType.EmployerBased))
                {
                    var national = apprenticeship.ApprenticeshipLocations.Any(x => x.National == true);

                    if (national)
                    {
                        model.SetApprenticeshipIsNational(national);
                    }
                    else
                    {
                        model.SetApprenticeshipLocationRegionIds(
                            apprenticeship.ApprenticeshipLocations?.SelectMany(x => x.Regions ?? new List <string>())?.ToList());
                    }
                }

                if (model.ApprenticeshipLocationType.Value.HasFlag(ApprenticeshipLocationType.ClassroomBased))
                {
                    var locations = apprenticeship.ApprenticeshipLocations.Where(x => x.ApprenticeshipLocationType.HasFlag(ApprenticeshipLocationType.ClassroomBased));

                    foreach (var l in locations)
                    {
                        model.SetClassroomLocationForVenue(
                            l.VenueId.Value,
                            l.VenueId.Value,
                            l.Radius.Value,
                            l.DeliveryModes);
                    }
                }
            }

            return(model);
        }
Example #2
0
        public async Task <FlowModel> Initialize(Guid providerId)
        {
            var model = new FlowModel();

            var provider = await _cosmosDbQueryDispatcher.ExecuteQuery(
                new Core.DataStore.CosmosDb.Queries.GetProviderById()
            {
                ProviderId = providerId
            });

            if (!string.IsNullOrEmpty(provider.MarketingInformation))
            {
                model.SetProviderDetails(Html.SanitizeHtml(provider.MarketingInformation));
            }

            var submission = await _sqlDbQueryDispatcher.ExecuteQuery(new GetLatestApprenticeshipQASubmissionForProvider()
            {
                ProviderId = providerId
            });

            if (submission != null)
            {
                var apprenticeshipId = submission.Apprenticeships.First().ApprenticeshipId;
                var apprenticeship   = await _sqlDbQueryDispatcher.ExecuteQuery(new GetApprenticeship()
                {
                    ApprenticeshipId = apprenticeshipId
                });

                model.SetApprenticeshipStandard(apprenticeship.Standard);

                model.SetApprenticeshipId(apprenticeship.ApprenticeshipId);

                model.SetApprenticeshipDetails(
                    apprenticeship.MarketingInformation,
                    apprenticeship.ApprenticeshipWebsite,
                    apprenticeship.ContactTelephone,
                    apprenticeship.ContactEmail,
                    apprenticeship.ContactWebsite);

                model.SetApprenticeshipLocationType(
                    ((apprenticeship.ApprenticeshipLocations.Any(l => l.Venue != null) ? ApprenticeshipLocationType.ClassroomBased : 0) |
                     (apprenticeship.ApprenticeshipLocations.Any(l => l.National == true || (l.SubRegionIds?.Count() ?? 0) > 0) ? ApprenticeshipLocationType.EmployerBased : 0)));

                if (model.ApprenticeshipLocationType.Value.HasFlag(ApprenticeshipLocationType.EmployerBased))
                {
                    var national = apprenticeship.ApprenticeshipLocations.Any(x => x.National == true);

                    if (national)
                    {
                        model.SetApprenticeshipIsNational(national);
                    }
                    else
                    {
                        model.SetApprenticeshipLocationRegionIds(
                            apprenticeship.ApprenticeshipLocations?.SelectMany(x => x.SubRegionIds ?? new List <string>())?.ToList());
                    }
                }

                if (model.ApprenticeshipLocationType.Value.HasFlag(ApprenticeshipLocationType.ClassroomBased))
                {
                    var locations = apprenticeship.ApprenticeshipLocations.Where(x => x.ApprenticeshipLocationType.HasFlag(ApprenticeshipLocationType.ClassroomBased));

                    foreach (var l in locations)
                    {
                        model.SetClassroomLocationForVenue(
                            l.Venue.VenueId,
                            l.Venue.VenueId,
                            l.Radius.Value,
                            l.DeliveryModes);
                    }
                }
            }

            return(model);
        }