private ImportMessage BuildMessage(string dataFileName, string metaFileName, Guid releaseId, string zipFileName = "") { var release = _context.Releases .Where(r => r.Id.Equals(releaseId)) .Include(r => r.Publication) .ThenInclude(p => p.Topic) .ThenInclude(t => t.Theme) .FirstOrDefault(); var importMessageRelease = _mapper.Map <Release>(release); return(new ImportMessage { SubjectId = _guidGenerator.NewGuid(), DataFileName = dataFileName, MetaFileName = metaFileName, Release = importMessageRelease, NumBatches = 1, BatchNo = 1, ArchiveFileName = zipFileName }); }
private Location LookupOrCreate( StatisticsDbContext context, Country country, Institution institution = null, LocalAuthority localAuthority = null, LocalAuthorityDistrict localAuthorityDistrict = null, LocalEnterprisePartnership localEnterprisePartnership = null, MayoralCombinedAuthority mayoralCombinedAuthority = null, Mat multiAcademyTrust = null, OpportunityArea opportunityArea = null, ParliamentaryConstituency parliamentaryConstituency = null, Region region = null, RscRegion rscRegion = null, Sponsor sponsor = null, Ward ward = null, PlanningArea planningArea = null) { var location = Lookup( context, country, institution, localAuthority, localAuthorityDistrict, localEnterprisePartnership, mayoralCombinedAuthority, multiAcademyTrust, opportunityArea, parliamentaryConstituency, region, rscRegion, sponsor, ward, planningArea); if (location == null) { var entityEntry = context.Location.Add(new Location { Id = _guidGenerator.NewGuid(), Country = country ?? Country.Empty(), Institution = institution ?? Institution.Empty(), LocalAuthority = localAuthority ?? LocalAuthority.Empty(), LocalAuthorityDistrict = localAuthorityDistrict ?? LocalAuthorityDistrict.Empty(), LocalEnterprisePartnership = localEnterprisePartnership ?? LocalEnterprisePartnership.Empty(), MayoralCombinedAuthority = mayoralCombinedAuthority ?? MayoralCombinedAuthority.Empty(), MultiAcademyTrust = multiAcademyTrust ?? Mat.Empty(), OpportunityArea = opportunityArea ?? OpportunityArea.Empty(), ParliamentaryConstituency = parliamentaryConstituency ?? ParliamentaryConstituency.Empty(), Region = region ?? Region.Empty(), RscRegion = rscRegion ?? RscRegion.Empty(), Sponsor = sponsor ?? Sponsor.Empty(), Ward = ward ?? Ward.Empty(), PlanningArea = planningArea ?? PlanningArea.Empty() }); return(entityEntry.Entity); } return(location); }
public async Task <Either <ActionResult, ReleaseViewModel> > CreateReleaseAsync(CreateReleaseViewModel createRelease) { return(await _persistenceHelper .CheckEntityExists <Publication>(createRelease.PublicationId) .OnSuccess(_userService.CheckCanCreateReleaseForPublication) .OnSuccess(async _ => await ValidateReleaseSlugUniqueToPublication(createRelease.Slug, createRelease.PublicationId)) .OnSuccess(async() => { var release = _mapper.Map <Release>(createRelease); release.Id = _guidGenerator.NewGuid(); if (createRelease.TemplateReleaseId.HasValue) { CreateGenericContentFromTemplate(createRelease.TemplateReleaseId.Value, release); } else { release.GenericContent = new List <ContentSection>(); } release.SummarySection = new ContentSection { Type = ContentSectionType.ReleaseSummary }; release.KeyStatisticsSection = new ContentSection { Type = ContentSectionType.KeyStatistics }; release.KeyStatisticsSecondarySection = new ContentSection { Type = ContentSectionType.KeyStatisticsSecondary }; release.HeadlinesSection = new ContentSection { Type = ContentSectionType.Headlines }; release.Created = DateTime.UtcNow; release.CreatedById = _userService.GetUserId(); await _context.Releases.AddAsync(release); await _context.SaveChangesAsync(); return await GetRelease(release.Id); })); }
private IEnumerable <(Indicator Indicator, string Column)> GetIndicators(IEnumerable <MetaRow> metaRows, Subject subject, StatisticsDbContext context) { var indicatorRows = metaRows.Where(row => row.ColumnType == ColumnType.Indicator).ToList(); indicatorRows.ForEach(row => { if (string.IsNullOrWhiteSpace(row.IndicatorGrouping)) { row.IndicatorGrouping = "Default"; } }); var indicatorGroups = indicatorRows .GroupBy(row => row.IndicatorGrouping) .ToDictionary(rows => rows.Key, rows => context.IndicatorGroup.FirstOrDefault(ig => ig.SubjectId == subject.Id && ig.Label == rows.Key) ?? new IndicatorGroup(rows.Key, subject) ); return(indicatorRows .Select(row => { indicatorGroups.TryGetValue(row.IndicatorGrouping, out var indicatorGroup); return ( indicator: context.Indicator.FirstOrDefault(i => i.IndicatorGroupId == indicatorGroup.Id && i.Label == row.Label && i.Unit == row.IndicatorUnit) ?? new Indicator { Id = _guidGenerator.NewGuid(), IndicatorGroup = indicatorGroup, Label = row.Label, Name = row.ColumnName, Unit = row.IndicatorUnit, DecimalPlaces = row.DecimalPlaces }, column: row.ColumnName ); })); }
public async Task <Either <ActionResult, Footnote> > CreateFootnote( Guid releaseId, string content, IReadOnlyCollection <Guid> filterIds, IReadOnlyCollection <Guid> filterGroupIds, IReadOnlyCollection <Guid> filterItemIds, IReadOnlyCollection <Guid> indicatorIds, IReadOnlyCollection <Guid> subjectIds) { return(await _contentPersistenceHelper .CheckEntityExists <Release>(releaseId) .OnSuccess(_userService.CheckCanUpdateRelease) .OnSuccess(async() => { var newFootnoteId = _guidGenerator.NewGuid(); var footnote = new Footnote { Id = newFootnoteId, Content = content, Subjects = CreateSubjectLinks(newFootnoteId, subjectIds), Filters = CreateFilterLinks(newFootnoteId, filterIds), FilterGroups = CreateFilterGroupLinks(newFootnoteId, filterGroupIds), FilterItems = CreateFilterItemLinks(newFootnoteId, filterItemIds), Indicators = CreateIndicatorsLinks(newFootnoteId, indicatorIds) }; await _context.Footnote.AddAsync(footnote); await _context.ReleaseFootnote.AddAsync(new ReleaseFootnote { ReleaseId = releaseId, Footnote = footnote }); await _context.SaveChangesAsync(); return await GetFootnote(releaseId, footnote.Id); })); }
private Observation ObservationFromCsv( StatisticsDbContext context, string[] line, List <string> headers, Subject subject, SubjectMeta subjectMeta, int csvRowNum) { var observationId = _guidGenerator.NewGuid(); return(new Observation { Id = observationId, FilterItems = GetFilterItems(context, line, headers, subjectMeta.Filters, observationId), GeographicLevel = GetGeographicLevel(line, headers), LocationId = GetLocationId(line, headers, context), Measures = GetMeasures(line, headers, subjectMeta.Indicators), SubjectId = subject.Id, TimeIdentifier = GetTimeIdentifier(line, headers), Year = GetYear(line, headers), CsvRow = csvRowNum }); }
protected AsyncNotification() : this(GuidGenerator.NewGuid()) { }
protected AsyncCommand() { CommandId = GuidGenerator.NewGuid(); }
private Location LookupOrCreate( StatisticsDbContext context, GeographicLevel geographicLevel, Country country, EnglishDevolvedArea?englishDevolvedArea, Institution?institution, LocalAuthority?localAuthority, LocalAuthorityDistrict?localAuthorityDistrict, LocalEnterprisePartnership?localEnterprisePartnership, MayoralCombinedAuthority?mayoralCombinedAuthority, Mat?multiAcademyTrust, OpportunityArea?opportunityArea, ParliamentaryConstituency?parliamentaryConstituency, PlanningArea?planningArea, Provider?provider, Region?region, RscRegion?rscRegion, School?school, Sponsor?sponsor, Ward?ward) { var location = Lookup( context, geographicLevel, country, englishDevolvedArea, institution, localAuthority, localAuthorityDistrict, localEnterprisePartnership, mayoralCombinedAuthority, multiAcademyTrust, opportunityArea, parliamentaryConstituency, planningArea, provider, region, rscRegion, school, sponsor, ward); if (location == null) { var entityEntry = context.Location.Add(new Location { Id = _guidGenerator.NewGuid(), GeographicLevel = geographicLevel, Country = country, EnglishDevolvedArea = englishDevolvedArea, Institution = institution, LocalAuthority = localAuthority, LocalAuthorityDistrict = localAuthorityDistrict, LocalEnterprisePartnership = localEnterprisePartnership, MayoralCombinedAuthority = mayoralCombinedAuthority, MultiAcademyTrust = multiAcademyTrust, OpportunityArea = opportunityArea, ParliamentaryConstituency = parliamentaryConstituency, PlanningArea = planningArea, Provider = provider, Region = region, RscRegion = rscRegion, School = school, Sponsor = sponsor, Ward = ward }); return(entityEntry.Entity); } return(location); }