private static List <TrainingDto> MapTraining(MatchedLearnerDataLockInfo matchedLearnerDataLockInfo)
 {
     return(matchedLearnerDataLockInfo.DataLockEvents.GroupBy(x => new
     {
         x.LearningAimReference,
         x.LearningAimStandardCode,
         x.LearningAimProgrammeType,
         x.LearningAimFrameworkCode,
         x.LearningAimPathwayCode,
         x.LearningAimFundingLineType,
         x.LearningStartDate,
         x.LearnerUln,
         x.Ukprn
     }).Select(dataLockEvent => new TrainingDto
     {
         Reference = dataLockEvent.Key.LearningAimReference,
         ProgrammeType = dataLockEvent.Key.LearningAimProgrammeType,
         StandardCode = dataLockEvent.Key.LearningAimStandardCode,
         FrameworkCode = dataLockEvent.Key.LearningAimFrameworkCode,
         PathwayCode = dataLockEvent.Key.LearningAimPathwayCode,
         FundingLineType = null,
         StartDate = dataLockEvent.Key.LearningStartDate.GetValueOrDefault(),
         PriceEpisodes = MapPriceEpisodes(dataLockEvent.Select(d => d.EventId), matchedLearnerDataLockInfo)
     }).ToList());
 }
        public MatchedLearnerDto Map(MatchedLearnerDataLockInfo matchedLearnerDataLockInfo)
        {
            if (matchedLearnerDataLockInfo == null || !matchedLearnerDataLockInfo.DataLockEvents.Any())
            {
                return(null);
            }

            var firstEvent = matchedLearnerDataLockInfo.DataLockEvents
                             .OrderByDescending(x => x.AcademicYear)
                             .ThenByDescending(x => x.CollectionPeriod)
                             .ThenBy(x => x.LearningStartDate)
                             .First();

            return(new MatchedLearnerDto
            {
                StartDate = firstEvent.LearningStartDate.GetValueOrDefault(),
                EventTime = firstEvent.EventTime,
                IlrSubmissionDate = firstEvent.IlrSubmissionDateTime,
                IlrSubmissionWindowPeriod = firstEvent.CollectionPeriod,
                AcademicYear = firstEvent.AcademicYear,
                Ukprn = firstEvent.Ukprn,
                Uln = firstEvent.LearnerUln,
                Training = MapTraining(matchedLearnerDataLockInfo)
            });
        }
        public void WhenNonPayablePeriodApprenticeshipIsNull_ThenExceptionNotThrown()
        {
            //Arrange

            var eventId = Guid.NewGuid();

            var testInput = new MatchedLearnerDataLockInfo
            {
                //TODO: Fix this
                //LatestSuccessfulJobs = new List<LatestSuccessfulJobModel>
                //{
                //    new LatestSuccessfulJobModel
                //    {
                //        CollectionPeriod = 1,
                //        AcademicYear = 2021,
                //        IlrSubmissionTime = DateTime.Now,
                //        Ukprn = 1234,
                //        JobId = 2,
                //        DcJobId = 2,
                //    }
                //},

                DataLockEvents = new List <DataLockEventModel>
                {
                    new DataLockEventModel
                    {
                        EventId                  = eventId,
                        AcademicYear             = 2021,
                        LearningAimPathwayCode   = 1,
                        LearningAimStandardCode  = 2,
                        LearningAimFrameworkCode = 31,
                        LearningAimProgrammeType = 4,
                        LearningAimReference     = "123",
                    }
                },
                DataLockEventNonPayablePeriods = new List <DataLockEventNonPayablePeriodModel>
                {
                    new DataLockEventNonPayablePeriodModel
                    {
                        Id                     = 1,
                        Amount                 = 0,
                        DataLockEventId        = eventId,
                        DeliveryPeriod         = 8,
                        PriceEpisodeIdentifier = "3-490-1-01/08/2020",
                        TransactionType        = 2
                    }
                }
            };

            //Act
            var sut = new MatchedLearnerDtoMapper();

            //Assert
            Assert.DoesNotThrow(() => { sut.Map(testInput); });
        }
        public void EventsFromDifferentApprenticeships_Programme__Should_NotBeGrouped()
        {
            var testInput = new MatchedLearnerDataLockInfo
            {
                //TODO: Fix this
                //LatestSuccessfulJobs = new List<LatestSuccessfulJobModel>
                //{
                //    new LatestSuccessfulJobModel
                //    {
                //        CollectionPeriod = 1,
                //        AcademicYear = 2021,
                //        IlrSubmissionTime = DateTime.Now,
                //        Ukprn = 1234,
                //        JobId = 2,
                //        DcJobId = 2,
                //    }
                //},

                DataLockEvents = new List <DataLockEventModel>
                {
                    new DataLockEventModel
                    {
                        AcademicYear             = 2021,
                        LearningAimPathwayCode   = 1,
                        LearningAimStandardCode  = 2,
                        LearningAimFrameworkCode = 31,
                        LearningAimProgrammeType = 4,
                        LearningAimReference     = "123",
                    },
                    new DataLockEventModel
                    {
                        AcademicYear             = 2021,
                        LearningAimPathwayCode   = 1,
                        LearningAimStandardCode  = 2,
                        LearningAimFrameworkCode = 3,
                        LearningAimProgrammeType = 4,
                        LearningAimReference     = "123",
                    }
                }
            };

            var sut = new MatchedLearnerDtoMapper();

            var actual = sut.Map(testInput);

            actual.Training.Should().HaveCount(2);
        }
        private static List <PeriodDto> MapPeriods(string priceEpisodeIdentifier, MatchedLearnerDataLockInfo matchedLearnerDataLockInfo)
        {
            var nonPayablePeriods = matchedLearnerDataLockInfo.DataLockEventNonPayablePeriods
                                    .Where(d => d.PriceEpisodeIdentifier == priceEpisodeIdentifier)
                                    .Select(nonPayablePeriod =>
            {
                var failures = matchedLearnerDataLockInfo.DataLockEventNonPayablePeriodFailures
                               .Where(f => f.DataLockEventNonPayablePeriodId ==
                                      nonPayablePeriod.DataLockEventNonPayablePeriodId).ToList();

                var apprenticeship = matchedLearnerDataLockInfo.Apprenticeships.FirstOrDefault(a => a.Id == failures.FirstOrDefault()?.ApprenticeshipId);

                return(new PeriodDto
                {
                    Period = nonPayablePeriod.DeliveryPeriod,
                    IsPayable = false,
                    DataLockFailures = failures.Select(f => (int)f.DataLockFailureId).ToList(),
                    AccountId = apprenticeship?.AccountId ?? 0,
                    ApprenticeshipId = apprenticeship?.Id,
                    ApprenticeshipEmployerType = apprenticeship?.ApprenticeshipEmployerType ?? 0,
                    TransferSenderAccountId = apprenticeship?.TransferSendingEmployerAccountId ?? 0
                });
            });

            var payablePeriods = matchedLearnerDataLockInfo.DataLockEventPayablePeriods
                                 .Where(d => d.PriceEpisodeIdentifier == priceEpisodeIdentifier)
                                 .Select(payablePeriod =>
            {
                var apprenticeship = matchedLearnerDataLockInfo.Apprenticeships.FirstOrDefault(a => a.Id == payablePeriod.ApprenticeshipId);

                return(new PeriodDto
                {
                    Period = payablePeriod.DeliveryPeriod,
                    IsPayable = true,
                    AccountId = apprenticeship?.AccountId ?? 0,
                    ApprenticeshipId = apprenticeship?.Id,
                    ApprenticeshipEmployerType = apprenticeship?.ApprenticeshipEmployerType ?? 0,
                    TransferSenderAccountId = apprenticeship?.TransferSendingEmployerAccountId ?? 0,
                });
            });

            return(payablePeriods.Union(nonPayablePeriods).ToList());
        }
コード例 #6
0
        public void Setup()
        {
            var testInput = new MatchedLearnerDataLockInfo
            {
                //TODO: Fix this
                //LatestSuccessfulJobs = new List<LatestSuccessfulJobModel>
                //{
                //    new LatestSuccessfulJobModel
                //    {
                //        CollectionPeriod = _expectedIlrSubmissionWindowPeriod,
                //        AcademicYear = _expectedAcademicYear,
                //        IlrSubmissionTime = _expectedIlrSubmissionDate,
                //        Ukprn = _expectedUkprn,
                //        JobId = 1,
                //        DcJobId = 1,
                //    }
                //},
                DataLockEvents = new List <DataLockEventModel>
                {
                    new DataLockEventModel
                    {
                        LearningStartDate     = _expectedLearningStartDate,
                        EventTime             = _expectedEventTime,
                        IlrSubmissionDateTime = _expectedIlrSubmissionDate,
                        CollectionPeriod      = _expectedIlrSubmissionWindowPeriod,
                        AcademicYear          = _expectedAcademicYear,
                        Ukprn                      = _expectedUkprn,
                        LearnerUln                 = _expectedUln,
                        LearningAimReference       = _expectedTrainingReference,
                        LearningAimProgrammeType   = _expectedTrainingProgrammeType,
                        LearningAimStandardCode    = _expectedTrainingStandardCode,
                        LearningAimFrameworkCode   = _expectedTrainingFrameworkCode,
                        LearningAimPathwayCode     = _expectedTrainingPathwayCode,
                        LearningAimFundingLineType = _expectedTrainingFundingLineType,
                    }
                },

                DataLockEventPriceEpisodes = new List <DataLockEventPriceEpisodeModel>
                {
                    new DataLockEventPriceEpisodeModel
                    {
                        StartDate              = _expectedPriceEpisodeStartDate,
                        ActualEndDate          = _expectedPriceEpisodeEndDate,
                        TotalNegotiatedPrice1  = 100m,
                        TotalNegotiatedPrice2  = 200m,
                        InstalmentAmount       = _expectedPriceEpisodeInstalmentAmount,
                        NumberOfInstalments    = _expectedPriceEpisodeNumberOfInstalments,
                        CompletionAmount       = _expectedPriceEpisodeCompletionAmount,
                        PriceEpisodeIdentifier = _expectedPriceEpisodeIdentifier,
                        EffectiveTotalNegotiatedPriceStartDate = _expectedTotalNegotiatedPriceStartDate
                    }
                },

                DataLockEventNonPayablePeriods = new List <DataLockEventNonPayablePeriodModel>
                {
                    new DataLockEventNonPayablePeriodModel
                    {
                        PriceEpisodeIdentifier = _expectedPriceEpisodeIdentifier,
                        DeliveryPeriod         = 2,
                    }
                },

                DataLockEventNonPayablePeriodFailures = new List <DataLockEventNonPayablePeriodFailureModel>
                {
                    new DataLockEventNonPayablePeriodFailureModel
                    {
                        ApprenticeshipId  = 123,
                        DataLockFailureId = 2,
                    },
                    new DataLockEventNonPayablePeriodFailureModel
                    {
                        ApprenticeshipId  = 123,
                        DataLockFailureId = 3,
                    },
                },

                Apprenticeships = new List <ApprenticeshipModel>
                {
                    new ApprenticeshipModel
                    {
                        Id = 123,
                        ApprenticeshipEmployerType = _expectedApprenticeshipEmployerType
                    },
                    new ApprenticeshipModel
                    {
                        Id = 456,
                        ApprenticeshipEmployerType = _expectedApprenticeshipEmployerType
                    }
                },

                DataLockEventPayablePeriods = new List <DataLockEventPayablePeriodModel>
                {
                    new DataLockEventPayablePeriodModel
                    {
                        PriceEpisodeIdentifier = _expectedPriceEpisodeIdentifier,
                        ApprenticeshipId       = 456,
                        DeliveryPeriod         = 1,
                    },
                }
            };

            var sut = new MatchedLearnerDtoMapper();

            _actual = sut.Map(testInput);
        }
コード例 #7
0
        public async Task <MatchedLearnerDataLockInfo> GetDataLockEvents(long ukprn, long uln)
        {
            var stopwatch = Stopwatch.StartNew();

            var transactionTypes = new List <byte> {
                1, 2, 3
            };

            var dataLockEvents = await _dataContext.DataLockEvent
                                 .Where(x =>
                                        x.LearningAimReference == "ZPROG001" &&
                                        x.Ukprn == ukprn &&
                                        x.LearnerUln == uln)
                                 .OrderBy(x => x.LearningStartDate)
                                 .ToListAsync();

            if (dataLockEvents == null)
            {
                stopwatch.Stop();
                _logger.LogInformation($"No Data for Uln: {uln}, Duration: {stopwatch.ElapsedMilliseconds}");
                return(new MatchedLearnerDataLockInfo());
            }

            _logger.LogInformation($"Started Getting DataLock Event Data from database for Uln: {uln}");

            var eventIds = dataLockEvents.Select(d => d.EventId).ToList();

            var dataLockEventPriceEpisodes = await _dataContext.DataLockEventPriceEpisode
                                             .Where(d => eventIds.Contains(d.DataLockEventId) && d.PriceEpisodeIdentifier != null)
                                             .OrderBy(p => p.StartDate)
                                             .ThenBy(p => p.PriceEpisodeIdentifier)
                                             .ToListAsync();

            var dataLockEventPayablePeriods = await _dataContext.DataLockEventPayablePeriod
                                              .Where(d => eventIds.Contains(d.DataLockEventId) && transactionTypes.Contains(d.TransactionType) && d.PriceEpisodeIdentifier != null && d.Amount != 0)
                                              .OrderBy(p => p.DeliveryPeriod)
                                              .ToListAsync();

            var dataLockEventNonPayablePeriods = await _dataContext.DataLockEventNonPayablePeriod
                                                 .Where(d => eventIds.Contains(d.DataLockEventId) && transactionTypes.Contains(d.TransactionType) && d.PriceEpisodeIdentifier != null && d.Amount != 0)
                                                 .OrderBy(p => p.DeliveryPeriod)
                                                 .ToListAsync();

            var dataLockEventNonPayablePeriodIds = dataLockEventNonPayablePeriods.Select(d => d.DataLockEventNonPayablePeriodId).ToList();

            var dataLockEventNonPayablePeriodFailures = new List <DataLockEventNonPayablePeriodFailureModel>();

            if (dataLockEventNonPayablePeriodIds.Any())
            {
                dataLockEventNonPayablePeriodFailures = await _dataContext.DataLockEventNonPayablePeriodFailures
                                                        .Where(d => dataLockEventNonPayablePeriodIds.Contains(d.DataLockEventNonPayablePeriodId))
                                                        .ToListAsync();
            }

            var apprenticeshipIds = dataLockEventPayablePeriods.Select(d => d.ApprenticeshipId)
                                    .Union(dataLockEventNonPayablePeriodFailures.Select(d => d.ApprenticeshipId))
                                    .Distinct()
                                    .ToList();

            var apprenticeshipDetails = new List <ApprenticeshipModel>();

            if (apprenticeshipIds.Any())
            {
                apprenticeshipDetails = await _dataContext.Apprenticeship.Where(a => apprenticeshipIds.Contains(a.Id)).ToListAsync();
            }

            var result = new MatchedLearnerDataLockInfo
            {
                DataLockEvents                        = dataLockEvents,
                DataLockEventPriceEpisodes            = dataLockEventPriceEpisodes,
                DataLockEventPayablePeriods           = dataLockEventPayablePeriods,
                DataLockEventNonPayablePeriods        = dataLockEventNonPayablePeriods,
                DataLockEventNonPayablePeriodFailures = dataLockEventNonPayablePeriodFailures,
                Apprenticeships                       = apprenticeshipDetails
            };

            stopwatch.Stop();

            _logger.LogInformation($"Finished Getting DataLock Event Data from database for Uln: {uln}, Duration: {stopwatch.ElapsedMilliseconds}");

            return(result);
        }
        private static List <PriceEpisodeDto> MapPriceEpisodes(IEnumerable <Guid> dataLockEventIds, MatchedLearnerDataLockInfo matchedLearnerDataLockInfo)
        {
            return(matchedLearnerDataLockInfo
                   .DataLockEventPriceEpisodes.Where(p => dataLockEventIds.Contains(p.DataLockEventId))
                   .GroupBy(x => new
            {
                x.PriceEpisodeIdentifier,
                x.AgreedPrice,
                x.StartDate,
                x.ActualEndDate,
                x.NumberOfInstalments,
                x.InstalmentAmount,
                x.CompletionAmount,
                x.EffectiveTotalNegotiatedPriceStartDate
            })
                   .Select(priceEpisode =>
            {
                var dataLockEvent = matchedLearnerDataLockInfo.DataLockEvents.Single(d =>
                                                                                     priceEpisode.First().DataLockEventId == d.EventId);

                return new PriceEpisodeDto
                {
                    AcademicYear = dataLockEvent.AcademicYear,
                    CollectionPeriod = dataLockEvent.CollectionPeriod,
                    Identifier = priceEpisode.Key.PriceEpisodeIdentifier,
                    AgreedPrice = priceEpisode.Key.AgreedPrice,
                    StartDate = ExtractEpisodeStartDateFromPriceEpisodeIdentifier(priceEpisode.Key.PriceEpisodeIdentifier),
                    EndDate = priceEpisode.Key.ActualEndDate,
                    NumberOfInstalments = priceEpisode.Key.NumberOfInstalments,
                    InstalmentAmount = priceEpisode.Key.InstalmentAmount,
                    CompletionAmount = priceEpisode.Key.CompletionAmount,
                    Periods = MapPeriods(priceEpisode.Key.PriceEpisodeIdentifier, matchedLearnerDataLockInfo),
                    TotalNegotiatedPriceStartDate = priceEpisode.Key.EffectiveTotalNegotiatedPriceStartDate
                };
            })
                   .OrderByDescending(x => x.AcademicYear)
                   .ThenByDescending(x => x.CollectionPeriod)
                   .ToList());
        }