Example #1
0
        /// <summary>
        /// Convert an internal representation of an org into the response object.
        /// </summary>
        /// <param name="orgGroup"></param>
        /// <param name="ukprn"></param>
        /// <param name="organisationType"></param>
        /// <returns>An organsation group response objct.</returns>
        private static OrganisationGroup ConvertToOrganisationGroup(OrgGroup orgGroup, string ukprn, OrganisationType organisationType)
        {
            var identifiers = new List <OrganisationIdentifier>
            {
                new OrganisationIdentifier
                {
                    Type  = OrganisationIdentifierType.UKPRN,
                    Value = ukprn
                }
            };

            if (organisationType == OrganisationType.LocalAuthority)
            {
                identifiers.Add(new OrganisationIdentifier
                {
                    Type  = OrganisationIdentifierType.LACode,
                    Value = orgGroup.Code
                });
            }

            return(new OrganisationGroup()
            {
                Type = organisationType,
                Name = orgGroup.Name,
                SearchableName = FundingController.SanitiseName(orgGroup.Name),
                Identifiers = identifiers
            });
        }
Example #2
0
        /// <summary>
        /// Get the provider funding ids to return for a feed entry.
        /// </summary>
        /// <param name="orgGroup"></param>
        /// <param name="period"></param>
        /// <param name="stream"></param>
        /// <param name="fundingVersion"></param>
        /// <returns>A list of provider funding ids.</returns>
        private static List <string> GetProviderFundingIds(OrgGroup orgGroup, FundingPeriod period, Stream stream, string fundingVersion,
                                                           OrganisationType[] organisationTypes, VariationReason[] variationReasons, string[] ukprns)
        {
            var returnList = new List <string>();

            // We don't have variation reasons yet
            if (variationReasons?.Any() == true)
            {
                return(returnList);
            }

            // If we are asking for anything but local authorities, there won't be any results
            if (organisationTypes?.Any() == true && organisationTypes?.Contains(OrganisationType.LocalAuthority) == false)
            {
                return(returnList);
            }

            foreach (var provider in orgGroup.Providers)
            {
                var ukprn = $"MOCKUKPRN{provider.LaEstablishmentNo}";

                if (ukprns?.Any() == true && ukprns?.Contains(ukprn) == false)
                {
                    continue;
                }

                returnList.Add($"{stream.Code}_{period.Code}_{ukprn}_{fundingVersion}");
            }

            return(returnList);
        }
Example #3
0
        /// <summary>
        /// Get organisations or organisaation groups from a CSV file.
        /// </summary>
        /// <param name="csvFileName">The filename to lookup from (relates to a sheet in the PE + Sports public spreadsheet).</param>
        /// <param name="groupByLa">Wether to group by LA or not.</param>
        /// <returns>A list or organisation groups.</returns>
        public List <OrgGroup> GetOrgsOrOrgGroups(string csvFileName, bool groupByLa)
        {
            var values     = GetDataFromCsv(csvFileName);
            var returnList = new List <OrgGroup>();

            if (groupByLa)
            {
                var laGroups = values.GroupBy(file => file.LaNo);

                foreach (var laGroup in laGroups)
                {
                    var la = new OrgGroup()
                    {
                        Code            = laGroup.First().LaNo,
                        Name            = laGroup.First().LaName,
                        AprilTotal      = laGroup.Sum(x => x.AprilPayment),
                        OctoberTotal    = laGroup.Sum(x => x.OctoberPayment),
                        TotalAllocation = laGroup.Sum(x => x.TotalAllocation),
                        Type            = csvFileName.Replace(".csv", string.Empty)
                    };

                    foreach (var item in laGroup)
                    {
                        var laProvider = new Provider()
                        {
                            LaEstablishmentNo = item.LaEstablishmentNo,
                            Name                = item.SchoolName,
                            OctoberPayment      = item.OctoberPayment,
                            AprilPayment        = item.AprilPayment,
                            EligiblePupilsCount = item.EligiblePupilsCount,
                            TotalAllocation     = item.TotalAllocation
                        };

                        la.Providers.Add(laProvider);
                    }

                    returnList.Add(la);
                }

                return(returnList);
            }

            foreach (var value in values)
            {
                var orgGroup = new OrgGroup()
                {
                    Code            = value.LaEstablishmentNo,
                    Name            = value.SchoolName,
                    AprilTotal      = value.AprilPayment,
                    OctoberTotal    = value.OctoberPayment,
                    TotalAllocation = value.TotalAllocation,
                    Type            = csvFileName.Replace(".csv", string.Empty),
                    Providers       = new List <Provider>
                    {
                        new Provider
                        {
                            LaEstablishmentNo = value.LaEstablishmentNo,
                            Name                = value.SchoolName,
                            OctoberPayment      = value.OctoberPayment,
                            AprilPayment        = value.AprilPayment,
                            EligiblePupilsCount = value.EligiblePupilsCount,
                            TotalAllocation     = value.TotalAllocation
                        }
                    }
                };

                returnList.Add(orgGroup);
            }

            return(returnList);
        }