public async Task <ValidateStatusChangeDateQueryResponse> Handle(ValidateStatusChangeDateQuery message)
        {
            ValidateQuery(message);

            var validationResult = new ValidationResult();

            var apprenticeship =
                await _commitmentsApi.GetEmployerApprenticeship(message.AccountId, message.ApprenticeshipId);

            var changeDateToUse = DetermineActualChangeDate(message, apprenticeship);

            if (changeDateToUse > new DateTime(_currentDate.Now.Year, _currentDate.Now.Month, 1))
            {
                validationResult.AddError(nameof(message.DateOfChange), "The stop date cannot be in the future");

                return(new ValidateStatusChangeDateQueryResponse {
                    ValidationResult = validationResult
                });
            }

            if (new DateTime(apprenticeship.StartDate.Value.Year, apprenticeship.StartDate.Value.Month, 1) > changeDateToUse)
            {
                validationResult.AddError(nameof(message.DateOfChange), "The stop month cannot be before the apprenticeship started");
                return(new ValidateStatusChangeDateQueryResponse {
                    ValidationResult = validationResult
                });
            }

            return(new ValidateStatusChangeDateQueryResponse {
                ValidationResult = validationResult, ValidatedChangeOfDate = changeDateToUse
            });
        }
        protected override async Task HandleCore(UpdateApprenticeshipStopDateCommand command)
        {
            var validationResult = _validator.Validate(command);

            if (!validationResult.IsValid())
            {
                throw new InvalidRequestException(validationResult.ValidationDictionary);
            }

            var stopDate = new ApprenticeshipStopDate
            {
                UserId            = command.UserId,
                LastUpdatedByInfo = new LastUpdateInfo {
                    EmailAddress = command.UserEmailAddress, Name = command.UserDisplayName
                },
                NewStopDate = command.NewStopDate
            };

            var apprenticeship = await
                                 _commitmentsApi.GetEmployerApprenticeship(command.EmployerAccountId, command.ApprenticeshipId);

            ValidateNewStopDate(command, apprenticeship);

            await _commitmentsApi.PutApprenticeshipStopDate(command.EmployerAccountId, command.CommitmentId, command.ApprenticeshipId, stopDate);

            await _providerEmailNotificationService.SendProviderApprenticeshipStopEditNotification(apprenticeship,
                                                                                                   command.NewStopDate);
        }
Beispiel #3
0
        protected override async Task HandleCore(DeleteApprenticeshipCommand message)
        {
            var validationResult = _validator.Validate(message);

            if (!validationResult.IsValid())
            {
                throw new InvalidRequestException(validationResult.ValidationDictionary);
            }

            var apprenticeship = await _commitmentsApi.GetEmployerApprenticeship(message.AccountId, message.ApprenticeshipId);

            var commitment = await
                             _commitmentsApi.GetEmployerCommitment(message.AccountId, apprenticeship.CommitmentId);

            await _commitmentsApi.DeleteEmployerApprenticeship(message.AccountId, message.ApprenticeshipId,
                                                               new DeleteRequest { UserId = message.UserId, LastUpdatedByInfo = new LastUpdateInfo {
                                                                                       EmailAddress = message.UserEmailAddress, Name = message.UserDisplayName
                                                                                   } });

            if (commitment.TransferSender?.TransferApprovalStatus ==
                Commitments.Api.Types.TransferApprovalStatus.Rejected)
            {
                await _providerEmailNotificationService.SendProviderTransferRejectedCommitmentEditNotification(
                    commitment);
            }
        }
        public async Task <GetApprenticeshipQueryResponse> Handle(GetApprenticeshipQueryRequest message)
        {
            var apprenticeship = await _commitmentsApi.GetEmployerApprenticeship(message.AccountId, message.ApprenticeshipId);

            return(new GetApprenticeshipQueryResponse
            {
                Apprenticeship = apprenticeship
            });
        }
Beispiel #5
0
        private async Task <Apprenticeship> GetApprenticeship(long employerAccountId, long apprenticeshipId)
        {
            try
            {
                return(await _commitmentsApiClient.GetEmployerApprenticeship(employerAccountId, apprenticeshipId));
            }
            catch (Exception e)
            {
                _logger.Warn(e, $"Unable to get Apprenticeship with Employer Account ID {employerAccountId} and " +
                             $"apprenticeship ID {apprenticeshipId} from commitments API.");
            }

            return(null);
        }
Beispiel #6
0
        protected override async Task HandleCore(UpdateApprenticeshipStatusCommand command)
        {
            var validationResult = _validator.Validate(command);

            if (!validationResult.IsValid())
            {
                throw new InvalidRequestException(validationResult.ValidationDictionary);
            }

            var apprenticeshipSubmission = new ApprenticeshipSubmission
            {
                PaymentStatus     = DeterminePaymentStatusForChange(command.ChangeType),
                DateOfChange      = command.DateOfChange,
                UserId            = command.UserId,
                MadeRedundant     = command.MadeRedundant,
                LastUpdatedByInfo = new LastUpdateInfo {
                    EmailAddress = command.UserEmailAddress, Name = command.UserDisplayName
                }
            };

            var apprenticeship = await _commitmentsApi.GetEmployerApprenticeship(command.EmployerAccountId, command.ApprenticeshipId);

            ValidateDateOfChange(apprenticeship, command, validationResult);

            await _commitmentsApi.PatchEmployerApprenticeship(command.EmployerAccountId, command.ApprenticeshipId, apprenticeshipSubmission);

            switch (command.ChangeType)
            {
            case ChangeStatusType.Stop: await _providerEmailNotificationService.SendProviderApprenticeshipStopNotification(apprenticeship, command.DateOfChange);

                break;

            case ChangeStatusType.Pause: await _providerEmailNotificationService.SendProviderApprenticeshipPauseNotification(apprenticeship, command.DateOfChange);

                break;

            case ChangeStatusType.Resume: await _providerEmailNotificationService.SendProviderApprenticeshipResumeNotification(apprenticeship, command.DateOfChange);

                break;
            }
        }