Пример #1
0
        public async Task <IActionResult> GetLocalAuthorityProvidersResultsForAllocations(string laCode, int startYear, int endYear, string allocationLineIds, HttpRequest request)
        {
            if (string.IsNullOrEmpty(laCode))
            {
                return(new BadRequestObjectResult("Missing la code"));
            }

            if (startYear == 0)
            {
                return(new BadRequestObjectResult("Missing start year"));
            }

            if (endYear == 0)
            {
                return(new BadRequestObjectResult("Missing end year"));
            }

            if (string.IsNullOrEmpty(allocationLineIds))
            {
                return(new BadRequestObjectResult("Missing allocation line ids"));
            }

            string[] allocationLineIdsArray = new string[0];

            if (!string.IsNullOrWhiteSpace(allocationLineIds))
            {
                allocationLineIdsArray = allocationLineIds.Split(",");
            }

            IList <string> allocationLineFilters = new List <string>();

            foreach (string allocationLineId in allocationLineIdsArray)
            {
                allocationLineFilters.Add($"allocationLineId eq '{allocationLineId}'");
            }

            SearchFeed <AllocationNotificationFeedIndex> searchFeed = await _feedsService.GetLocalAuthorityFeeds(laCode, startYear, endYear, allocationLineFilters);

            if (searchFeed == null || searchFeed.Entries.IsNullOrEmpty())
            {
                return(new NotFoundResult());
            }

            IEnumerable <AllocationNotificationFeedIndex> entries = ValidateFeedsForLaCode(searchFeed.Entries);

            if (entries.IsNullOrEmpty())
            {
                return(new NotFoundResult());
            }

            entries = entries.OrderByDescending(o => o.AllocationVersionNumber).DistinctBy(m => m.ProviderId);

            LocalAuthorityResultsSummary localAuthorityResultsSummary = CreateLocalAuthorityResultsSummary(entries, request);

            return(Formatter.ActionResult(request, localAuthorityResultsSummary));
        }
Пример #2
0
        public object GetExamples()
        {
            LocalAuthorityResultsSummary summary = JsonConvert.DeserializeObject <LocalAuthorityResultsSummary>(Properties.Resources.V1_Sample_LocalAuthority_Results);

            foreach (LocalAuthorityResultSummary localAuthorityResultSummary in summary.LocalAuthorities)
            {
                foreach (LocalAuthorityProviderResultSummary localAuthorityProviderResultSummary in localAuthorityResultSummary.Providers)
                {
                    localAuthorityProviderResultSummary.Provider.ProviderVariation = ProviderVariationExample.GetProviderVariationExample();
                }
            }
            return(summary);
        }
Пример #3
0
        private LocalAuthorityResultsSummary CreateLocalAuthorityResultsSummary(IEnumerable <AllocationNotificationFeedIndex> entries, HttpRequest request)
        {
            ///TODO: Require permanent fix
            entries = entries.Where(m => m.ProviderUkPrn != "10080459");

            IEnumerable <IGrouping <string, AllocationNotificationFeedIndex> > localAuthorityResultSummaryGroups = entries.GroupBy(m => m.LaCode);

            AllocationNotificationFeedIndex firstEntry = entries.First();

            LocalAuthorityResultsSummary localAuthorityResultsSummary = new LocalAuthorityResultsSummary
            {
                FundingPeriod = $"{firstEntry.FundingPeriodStartYear}-{firstEntry.FundingPeriodEndYear}"
            };

            foreach (IGrouping <string, AllocationNotificationFeedIndex> localAuthorityResultSummaryGroup in localAuthorityResultSummaryGroups)
            {
                AllocationNotificationFeedIndex firstFeedIndex = localAuthorityResultSummaryGroup.First();

                LocalAuthorityResultSummary localAuthorityResultSummary = new LocalAuthorityResultSummary
                {
                    LANo   = firstFeedIndex.LaCode,
                    LAName = firstFeedIndex.Authority
                };

                foreach (AllocationNotificationFeedIndex feedIndex in localAuthorityResultSummaryGroup)
                {
                    LocalAuthorityProviderResultSummary resultSummary = new LocalAuthorityProviderResultSummary
                    {
                        Provider = new AllocationProviderModel
                        {
                            ProviderId             = feedIndex.ProviderId,
                            Name                   = feedIndex.ProviderName,
                            LegalName              = feedIndex.ProviderLegalName,
                            UkPrn                  = feedIndex.ProviderUkPrn,
                            Upin                   = feedIndex.ProviderUpin,
                            Urn                    = feedIndex.ProviderUrn,
                            DfeEstablishmentNumber = feedIndex.DfeEstablishmentNumber,
                            EstablishmentNumber    = feedIndex.EstablishmentNumber,
                            LaCode                 = feedIndex.LaCode,
                            LocalAuthority         = feedIndex.Authority,
                            Type                   = feedIndex.ProviderType,
                            SubType                = feedIndex.SubProviderType,
                            OpenDate               = feedIndex.ProviderOpenDate,
                            CloseDate              = feedIndex.ProviderClosedDate,
                            CrmAccountId           = feedIndex.CrmAccountId,
                            NavVendorNo            = feedIndex.NavVendorNo,
                            Status                 = feedIndex.ProviderStatus
                        }
                    };

                    IEnumerable <IGrouping <string, AllocationNotificationFeedIndex> > fundingPeriodResultSummaryGroups = localAuthorityResultSummaryGroup.GroupBy(m => m.FundingPeriodId);

                    foreach (IGrouping <string, AllocationNotificationFeedIndex> fundingPeriodResultSummaryGroup in fundingPeriodResultSummaryGroups)
                    {
                        AllocationNotificationFeedIndex fundingPeriodFeedIndex = fundingPeriodResultSummaryGroup.First();

                        FundingPeriodResultSummary fundingPeriodResultSummary = new FundingPeriodResultSummary
                        {
                            Period = new Period
                            {
                                Id        = fundingPeriodFeedIndex.FundingPeriodId,
                                Name      = fundingPeriodFeedIndex.FundingStreamPeriodName,
                                StartYear = fundingPeriodFeedIndex.FundingPeriodStartYear,
                                EndYear   = fundingPeriodFeedIndex.FundingPeriodEndYear
                            },
                            FundingStream = new AllocationFundingStreamModel
                            {
                                Id         = feedIndex.FundingStreamId,
                                Name       = feedIndex.FundingStreamName,
                                ShortName  = feedIndex.FundingStreamShortName,
                                PeriodType = new AllocationFundingStreamPeriodTypeModel
                                {
                                    Id         = feedIndex.FundingStreamPeriodId,
                                    Name       = feedIndex.FundingStreamPeriodName,
                                    StartDay   = feedIndex.FundingStreamStartDay,
                                    StartMonth = feedIndex.FundingStreamStartMonth,
                                    EndDay     = feedIndex.FundingStreamEndDay,
                                    EndMonth   = feedIndex.FundingStreamEndMonth
                                }
                            }
                        };

                        foreach (AllocationNotificationFeedIndex allocationFeedIndex in fundingPeriodResultSummaryGroup)
                        {
                            if (allocationFeedIndex.ProviderId != resultSummary.Provider.ProviderId)
                            {
                                continue;
                            }

                            AllocationResultWIthProfilePeriod allocationResultWIthProfilePeriod = new AllocationResultWIthProfilePeriod
                            {
                                AllocationLine = new AllocationLine
                                {
                                    Id               = allocationFeedIndex.AllocationLineId,
                                    Name             = allocationFeedIndex.AllocationLineName,
                                    ShortName        = allocationFeedIndex.AllocationLineShortName,
                                    FundingRoute     = allocationFeedIndex.AllocationLineFundingRoute,
                                    ContractRequired = allocationFeedIndex.AllocationLineContractRequired ? "Y" : "N"
                                },
                                AllocationStatus        = allocationFeedIndex.AllocationStatus,
                                AllocationVersionNumber = (ushort)allocationFeedIndex.AllocationVersionNumber,
                                AllocationAmount        = Convert.ToDecimal(allocationFeedIndex.AllocationAmount)
                            };

                            resultSummary.AllocationValue += allocationResultWIthProfilePeriod.AllocationAmount;

                            ProfilingPeriod[] profilingPeriods = JsonConvert.DeserializeObject <ProfilingPeriod[]>(allocationFeedIndex.ProviderProfiling);

                            foreach (ProfilingPeriod profilingPeriod in profilingPeriods)
                            {
                                allocationResultWIthProfilePeriod.ProfilePeriods = allocationResultWIthProfilePeriod.ProfilePeriods.Concat(new[]
                                {
                                    new ProfilePeriod
                                    {
                                        Period             = profilingPeriod.Period,
                                        Occurrence         = profilingPeriod.Occurrence,
                                        PeriodYear         = profilingPeriod.Year.ToString(),
                                        PeriodType         = profilingPeriod.Type,
                                        ProfileValue       = profilingPeriod.Value,
                                        DistributionPeriod = profilingPeriod.DistributionPeriod
                                    }
                                }).ToArraySafe();
                            }

                            fundingPeriodResultSummary.Allocations = fundingPeriodResultSummary.Allocations.Concat(new[]
                            {
                                allocationResultWIthProfilePeriod
                            }).ToArraySafe();
                        }

                        resultSummary.FundingPeriods = resultSummary.FundingPeriods.Concat(new[]
                        {
                            fundingPeriodResultSummary
                        }).ToArraySafe();
                    }

                    localAuthorityResultSummary.Providers = localAuthorityResultSummary.Providers.Concat(new[] { resultSummary }).ToArraySafe();
                }

                localAuthorityResultSummary.TotalAllocation = localAuthorityResultSummary.Providers.Sum(m => m.AllocationValue);

                localAuthorityResultsSummary.LocalAuthorities = localAuthorityResultsSummary.LocalAuthorities.Concat(new[] { localAuthorityResultSummary }).ToArraySafe();
            }

            localAuthorityResultsSummary.TotalAllocation = localAuthorityResultsSummary.LocalAuthorities.Sum(m => m.TotalAllocation);

            return(localAuthorityResultsSummary);
        }
        public object GetExamples()
        {
            LocalAuthorityResultsSummary summary = JsonConvert.DeserializeObject <LocalAuthorityResultsSummary>(Properties.Resources.V1_Sample_LocalAuthority_Results);

            return(summary);
        }