private async Task <SpecificationDatasetRelationshipsViewModel> PopulateViewModel(SpecificationSummary specification)
        {
            SpecificationSummaryViewModel vm = _mapper.Map <SpecificationSummaryViewModel>(specification);
            SpecificationDatasetRelationshipsViewModel viewModel = new SpecificationDatasetRelationshipsViewModel(vm);

            ApiResponse <IEnumerable <DatasetSpecificationRelationshipViewModel> > apiResponse = await _datasetsApiClient.GetRelationshipsBySpecificationId(specification.Id);

            if (apiResponse.StatusCode != HttpStatusCode.OK || apiResponse.Content == null)
            {
                return(null);
            }

            viewModel.Items = apiResponse.Content.Select(m => new SpecificationDatasetRelationshipItemViewModel
            {
                DatasetId               = m.DatasetId,
                DatasetName             = m.DatasetName,
                DefinitionName          = m.Definition != null ? m.Definition.Name : string.Empty,
                DefinitionId            = m.Definition != null ? m.Definition.Id : string.Empty,
                DefinitionDescription   = m.Definition?.Description ?? string.Empty,
                DatasetVersion          = m.Version ?? 0,
                RelationName            = m.Name,
                RelationshipId          = m.Id,
                RelationshipDescription = m.RelationshipDescription,
                IsProviderData          = m.IsProviderData,
                IsLatestVersion         = m.IsLatestVersion,
                LastUpdatedDate         = m.LastUpdatedDate,
                LastUpdatedAuthorName   = string.IsNullOrWhiteSpace(m.LastUpdatedAuthor?.Name) ? "Unknown" : m.LastUpdatedAuthor.Name,
            }).OrderBy(_ => _.RelationName);

            return(viewModel);
        }
Ejemplo n.º 2
0
        private async Task <SpecificationDatasetRelationshipsViewModel> PopulateViewModel(SpecificationSummary specification)
        {
            SpecificationSummaryViewModel vm = _mapper.Map <SpecificationSummaryViewModel>(specification);
            SpecificationDatasetRelationshipsViewModel viewModel = new SpecificationDatasetRelationshipsViewModel(vm);

            ApiResponse <IEnumerable <DatasetSpecificationRelationshipModel> > apiResponse = await _datasetsApiClient.GetDatasetSpecificationRelationshipsBySpecificationId(specification.Id);

            if (apiResponse.StatusCode != HttpStatusCode.OK || apiResponse.Content == null)
            {
                _logger.Error($"Failed to fetch specification relationships for specification id: {specification.Id}");

                return(null);
            }

            viewModel.Items = apiResponse.Content.Select(m => new SpecificationDatasetRelationshipItemViewModel
            {
                DatasetId               = m.DatasetId,
                DatasetName             = m.DatasetName,
                DefinitionName          = m.Definition != null ? m.Definition.Name : string.Empty,
                DefinitionId            = m.Definition != null ? m.Definition.Id : string.Empty,
                DefinitionDescription   = m.Definition != null ? m.Definition.Description : string.Empty,
                DatasetVersion          = m.Version.HasValue ? m.Version.Value : 0,
                RelationName            = m.Name,
                RelationshipId          = m.Id,
                RelationshipDescription = m.RelationshipDescription,
                IsProviderData          = m.IsProviderData
            });

            return(viewModel);
        }
Ejemplo n.º 3
0
        public SpecificationDatasetRelationshipsViewModel(SpecificationSummaryViewModel specification)
        {
            Items = Enumerable.Empty <SpecificationDatasetRelationshipItemViewModel>();

            Specification = specification;
            SpecificationTrimmedViewModel = ToSpecificationTrimmedViewModel(specification);
        }
        public async Task <IActionResult> OnGetAsync(string specificationId, string fundingPeriodId, string fundingStreamId)
        {
            Guard.IsNullOrWhiteSpace(specificationId, nameof(specificationId));
            Guard.IsNullOrWhiteSpace(fundingPeriodId, nameof(fundingPeriodId));
            Guard.IsNullOrWhiteSpace(fundingStreamId, nameof(fundingStreamId));

            SpecificationId = specificationId;

            FundingPeriodId = fundingPeriodId;

            FundingStreamId = fundingStreamId;

            ApiResponse <Specification> specificationLookupTask = await _specsClient.GetSpecification(specificationId);

            IActionResult specificationLookupError = specificationLookupTask.IsSuccessOrReturnFailureResult("Specification");

            if (specificationLookupError == null)
            {
                SpecificationViewModel = new SpecificationSummaryViewModel
                {
                    Name           = specificationLookupTask.Content.Name,
                    FundingStreams = specificationLookupTask.Content.FundingStreams.Select(m => new ReferenceViewModel(m.Id, m.Name)),
                    FundingPeriod  = new ReferenceViewModel(specificationLookupTask.Content.FundingPeriod.Id, specificationLookupTask.Content.FundingPeriod.Name)
                };

                return(Page());
            }
            else
            {
                return(specificationLookupError);
            }
        }
Ejemplo n.º 5
0
 public SpecificationViewModel ToSpecificationTrimmedViewModel(SpecificationSummaryViewModel specificationSummaryViewModel)
 {
     return(new SpecificationViewModel()
     {
         FundingPeriod = specificationSummaryViewModel.FundingPeriod,
         Description = specificationSummaryViewModel.Description,
         FundingStreams = specificationSummaryViewModel.FundingStreams,
         Id = specificationSummaryViewModel.Id,
         Name = specificationSummaryViewModel.Name
     });
 }