Пример #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));
        }