Exemplo n.º 1
0
        public async Task <IActionResult> GetAdditionalCalculationsByProviderId(
            string specificationId,
            CalculationType calculationType,
            int pageNumber,
            [FromQuery] string searchTerm,
            [FromQuery] string status,
            [FromRoute] string providerId)
        {
            Guard.ArgumentNotNull(specificationId, nameof(specificationId));

            PublishStatus?publishStatus = null;

            if (!string.IsNullOrEmpty(status) && status != "All")
            {
                publishStatus = (PublishStatus)Enum.Parse(typeof(PublishStatus), status);
            }

            ApiResponse <SearchResults <CalculationSearchResult> > result =
                await _calcClient.SearchCalculationsForSpecification(specificationId,
                                                                     calculationType, publishStatus, searchTerm, pageNumber);

            ApiResponse <ProviderResultResponse> providerResultResponse =
                await _resultsApiClient.GetProviderResults(providerId, specificationId);

            IActionResult providerResultResponseErrorResult = providerResultResponse.IsSuccessOrReturnFailureResult("GetProviderResults");

            if (providerResultResponseErrorResult != null)
            {
                return(providerResultResponseErrorResult);
            }

            if (result.StatusCode == HttpStatusCode.OK)
            {
                var calcSearchResults = result.Content;

                IEnumerable <AdditionalCalculationSearchResultViewModel> additionalCalcs =
                    calcSearchResults.Results.Select(c =>
                                                     new AdditionalCalculationSearchResultViewModel
                {
                    Id              = c.Id,
                    Name            = c.Name,
                    ValueType       = c.ValueType,
                    Value           = providerResultResponse.Content.CalculationResults.FirstOrDefault(calcResult => calcResult.Calculation.Id == c.Id)?.Value,
                    LastUpdatedDate = c.LastUpdatedDate
                });

                var calcs = new SearchResults <AdditionalCalculationSearchResultViewModel>
                {
                    TotalCount      = calcSearchResults.TotalCount,
                    Results         = additionalCalcs,
                    Facets          = calcSearchResults.Facets,
                    TotalErrorCount = calcSearchResults.TotalErrorCount,
                };

                return(Ok(calcs));
            }

            return(BadRequest(result.Content));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetCalculationsForSpecification(string specificationId,
                                                                          CalculationType calculationType, int pageNumber, [FromQuery] string searchTerm, [FromQuery] string status)
        {
            Guard.ArgumentNotNull(specificationId, nameof(specificationId));

            PublishStatus?publishStatus = null;

            if (!string.IsNullOrEmpty(status) && status != "All")
            {
                publishStatus = (PublishStatus)Enum.Parse(typeof(PublishStatus), status);
            }

            ApiResponse <SearchResults <CalculationSearchResult> > result =
                await _calcClient.SearchCalculationsForSpecification(specificationId,
                                                                     calculationType, publishStatus, searchTerm, pageNumber);

            if (result.StatusCode == HttpStatusCode.OK)
            {
                return(Ok(result.Content));
            }

            return(BadRequest(result.Content));
        }