public async Task Handle(ApprenticeshipMessage message, string allowProjectionsEndpoint) { if (message.LearnerId <= 0) { throw new InvalidOperationException("Apprenticeship requires LearnerId"); } if (message.CourseLevel <= 0) { throw new InvalidOperationException("Apprenticeship requires CourseLevel"); } var commitment = await _repository.Get(message.EmployerAccountId, message.ApprenticeshipId); var commitmentModel = _apprenticeshipMapping.MapToCommitment(message); if (!commitment.RegisterCommitment(commitmentModel)) { _logger.Info($"Not storing the employer commitment. Employer: {message.EmployerAccountId}, ApprenticeshipId: {message.ApprenticeshipId} "); return; } await _repository.Store(commitment); _logger.Info($"Finished adding the employer commitment. Employer: {message.EmployerAccountId}, ApprenticeshipId: {message.ApprenticeshipId}"); _queueService.SendMessageWithVisibilityDelay(message, allowProjectionsEndpoint); }
public CommitmentModel MapToCommitment(ApprenticeshipMessage message) { var model = new CommitmentModel { EmployerAccountId = message.EmployerAccountId, ApprenticeshipId = message.ApprenticeshipId, LearnerId = message.LearnerId, StartDate = message.StartDate, PlannedEndDate = message.PlannedEndDate, ActualEndDate = message.ActualEndDate, CompletionAmount = message.CompletionAmount, MonthlyInstallment = message.MonthlyInstallment, NumberOfInstallments = (short)message.NumberOfInstallments, ProviderId = message.ProviderId, ProviderName = message.ProviderName, ApprenticeName = message.ApprenticeName, CourseName = message.CourseName, CourseLevel = message.CourseLevel, SendingEmployerAccountId = message.SendingEmployerAccountId ?? message.EmployerAccountId, FundingSource = message.FundingSource, UpdatedDateTime = DateTime.UtcNow, HasHadPayment = false }; return(model); }
public static async Task Run( [QueueTrigger(QueueNames.StoreApprenticeships)] ApprenticeshipMessage message, ExecutionContext executionContext, TraceWriter writer) { await FunctionRunner.Run <StoreApprenticeships>(writer, executionContext, async (container, logger) => { logger.Debug($"Storing apprenticeship. Account: {message.EmployerAccountId}, apprenticeship id: {message.ApprenticeshipId}"); var handler = container.GetInstance <StoreCommitmentHandler>(); message.ProjectionSource = ProjectionSource.Commitment; await handler.Handle(message, QueueNames.AllowProjection); logger.Info($"Stored commitment. Apprenticeship id: {message.ApprenticeshipId}"); }); }