public async Task <string[]> Handle(GatherStandardsRequest request, CancellationToken cancellationToken) { var minimumHoursBetweenCollations = 23; var dateOfLastCollation = await _standardRepository.GetDateOfLastStandardCollation(); if (dateOfLastCollation == null || dateOfLastCollation.Value.AddHours(minimumHoursBetweenCollations) < DateTime.Now) { try { _unitOfWork.Begin(); var ifaStandards = await _standardService.GetIfaStandards(); var approvedIfaStandards = ifaStandards.Where(p => p.LarsCode != 0).ToList(); _logger.LogInformation("Gathering approved Standard details from all sources in the handler"); var approvedStandardDetails = await _standardService.GatherAllApprovedStandardDetails(approvedIfaStandards); _logger.LogInformation("Upserting gathered approved Standards"); var approvedResponse = await _standardRepository.UpsertApprovedStandards(approvedStandardDetails.ToList()); _logger.LogInformation("Processing of approved Standards upsert complete"); var nonApprovedIfaStandards = ifaStandards.Where(p => p.LarsCode == 0).ToList(); _logger.LogInformation("Gathering non-approved Standard details from all sources in the handler"); var nonApprovedStandardDetails = _standardService.GatherAllNonApprovedStandardDetails(nonApprovedIfaStandards); _logger.LogInformation("Upserting gathered non-approved Standards"); var nonApprovedResponse = await _standardRepository.UpsertNonApprovedStandards(nonApprovedStandardDetails.ToList()); _logger.LogInformation("Processing of non-approved Standards upsert complete"); _unitOfWork.Commit(); return(new string[] { approvedResponse, nonApprovedResponse }); } catch (Exception ex) { _logger.LogError(ex, "Processing of Standards could not be completed"); _unitOfWork.Rollback(); throw; } } return(new string[] { $"Collation was last done on {dateOfLastCollation.Value}. There is a minimum of {minimumHoursBetweenCollations} hours between collation runs" }); }
public async Task UpsertStandardCollations(IEnumerable <StandardDetailResponse> standards) { Func <StandardDetailResponse, StandardCollation> MapGetStandardsListItemToStandardCollation = source => new StandardCollation { StandardId = source.LarsCode, ReferenceNumber = source.IfateReferenceNumber, Title = source.Title, Options = source.Options, StandardData = new StandardData { Category = source.Route, IfaStatus = source.Status, EqaProviderName = source.EqaProvider?.Name, EqaProviderContactName = source.EqaProvider?.ContactName, EqaProviderContactEmail = source.EqaProvider?.ContactEmail, EqaProviderWebLink = source.EqaProvider?.WebLink, IntegratedDegree = source.IntegratedDegree, EffectiveFrom = source.StandardDates.EffectiveFrom, EffectiveTo = source.StandardDates.EffectiveTo, Level = source.Level, LastDateForNewStarts = source.StandardDates.LastDateStarts, IfaOnly = source.LarsCode == 0, Duration = source.TypicalDuration, MaxFunding = source.MaxFunding, Trailblazer = source.TrailBlazerContact, PublishedDate = source.VersionDetail.ApprovedForDelivery, IsPublished = source.LarsCode > 0, Ssa2 = source.SectorSubjectAreaTier2Description, OverviewOfRole = source.OverviewOfRole, IsActiveStandardInWin = source.IsActive, AssessmentPlanUrl = source.AssessmentPlanUrl, StandardPageUrl = source.StandardPageUrl } }; var standardCollations = standards.Select(MapGetStandardsListItemToStandardCollation).ToList(); await standardRepository.UpsertApprovedStandards(standardCollations); }