protected override async Task HandleCore(CreateAccountEventCommand command)
        {
            _logger.Info($"Received message {command.Event}", accountId: command.ResourceUri, @event: command.Event);

            Validate(command);

            try
            {
                var newAccountEvent = new AccountEvent
                {
                    Event       = command.Event,
                    CreatedOn   = DateTime.UtcNow,
                    ResourceUri = command.ResourceUri
                };

                await _accountEventRepository.Create(newAccountEvent);

                _logger.Info($"Finished processing message {command.Event}");
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"Error processing message {command.Event} - {ex.Message}", accountId: command.ResourceUri, @event: command.Event);
                throw;
            }
        }
        protected override async Task HandleCore(CreateAgreementEventCommand command)
        {
            _logger.Info($"Received message {command.Event}", providerId: command.ProviderId, @event: command.Event);

            Validate(command);

            try
            {
                var newAgreementEvent = new AgreementEvent
                {
                    Event        = command.Event,
                    CreatedOn    = DateTime.UtcNow,
                    ProviderId   = command.ProviderId,
                    ContractType = command.ContractType
                };

                await _agreementEventRepository.Create(newAgreementEvent);

                _logger.Info($"Finished processing message {command.Event}");
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"Error processing message {command.Event} - {ex.Message}", providerId: command.ProviderId, @event: command.Event);
                throw;
            }
        }
        protected override async Task HandleCore(CreateApprenticeshipEventCommand command)
        {
            _logger.Info($"Received message {command.Event}", accountId: command.EmployerAccountId, providerId: command.ProviderId, @event: command.Event);

            var validationResult = _validator.Validate(command);

            if (!validationResult.IsValid)
            {
                throw new ValidationException(validationResult.Errors);
            }

            try
            {
                var newApprenticeshipEvent = new ApprenticeshipEvent
                {
                    Event                            = command.Event,
                    CreatedOn                        = DateTime.UtcNow,
                    ApprenticeshipId                 = command.ApprenticeshipId,
                    PaymentStatus                    = command.PaymentStatus,
                    PausedOnDate                     = command.PausedOnDate,
                    StoppedOnDate                    = command.StoppedOnDate,
                    AgreementStatus                  = command.AgreementStatus,
                    ProviderId                       = command.ProviderId,
                    LearnerId                        = command.LearnerId,
                    EmployerAccountId                = command.EmployerAccountId,
                    TrainingType                     = command.TrainingType,
                    TrainingId                       = command.TrainingId,
                    TrainingStartDate                = command.TrainingStartDate,
                    TrainingEndDate                  = command.TrainingEndDate,
                    TrainingTotalCost                = command.TrainingTotalCost,
                    PaymentOrder                     = command.PaymentOrder,
                    LegalEntityId                    = command.LegalEntityId,
                    LegalEntityOrganisationType      = command.LegalEntityOrganisationType,
                    AccountLegalEntityPublicHashedId = command.AccountLegalEntityPublicHashedId,
                    LegalEntityName                  = command.LegalEntityName,
                    EffectiveFrom                    = command.EffectiveFrom,
                    EffectiveTo                      = command.EffectiveTo,
                    DateOfBirth                      = command.DateOfBirth,
                    PriceHistory                     = command.PriceHistory,
                    TransferSenderId                 = command.TransferSenderId,
                    TransferSenderName               = command.TransferSenderName,
                    TransferApprovalStatus           = command.TransferApprovalStatus,
                    TransferApprovalActionedOn       = command.TransferApprovalActionedOn
                };

                await _apprenticeshipEventRepository.Create(newApprenticeshipEvent);

                _logger.Info($"Finished processing message {command.Event}", accountId: command.EmployerAccountId, providerId: command.ProviderId, @event: command.Event);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"Error processing message {command.Event} - {ex.Message}", accountId: command.EmployerAccountId, providerId: command.ProviderId, @event: command.Event);
                throw;
            }
        }
        public async Task CreateEvent(ApprenticeshipEvent request)
        {
            try
            {
                _logger.Info($"Creating Apprenticeship Event ({request.Event}) for Employer: {request.EmployerAccountId}, Provider: {request.ProviderId}", @event: request.Event, accountId: request.EmployerAccountId, providerId: request.ProviderId);

                await _mediator.SendAsync(new CreateApprenticeshipEventCommand
                {
                    Event                            = request.Event,
                    ApprenticeshipId                 = request.ApprenticeshipId,
                    PaymentStatus                    = (Domain.Entities.PaymentStatus)request.PaymentStatus,
                    PausedOnDate                     = request.PausedOnDate,
                    StoppedOnDate                    = request.StoppedOnDate,
                    AgreementStatus                  = (Domain.Entities.AgreementStatus)request.AgreementStatus,
                    ProviderId                       = request.ProviderId,
                    LearnerId                        = request.LearnerId,
                    EmployerAccountId                = request.EmployerAccountId,
                    TrainingType                     = (Domain.Entities.TrainingTypes)request.TrainingType,
                    TrainingId                       = request.TrainingId,
                    TrainingStartDate                = request.TrainingStartDate,
                    TrainingEndDate                  = request.TrainingEndDate,
                    TrainingTotalCost                = request.TrainingTotalCost,
                    PaymentOrder                     = request.PaymentOrder,
                    LegalEntityId                    = request.LegalEntityId,
                    LegalEntityName                  = request.LegalEntityName,
                    LegalEntityOrganisationType      = request.LegalEntityOrganisationType,
                    AccountLegalEntityPublicHashedId = request.AccountLegalEntityPublicHashedId,
                    EffectiveFrom                    = request.EffectiveFrom,
                    EffectiveTo                      = request.EffectiveTo,
                    DateOfBirth                      = request.DateOfBirth,
                    PriceHistory                     = request.PriceHistory?.Select(ToDomainModel).ToList() ?? new List <Domain.Entities.PriceHistory>(),
                    TransferSenderId                 = request.TransferSenderId,
                    TransferSenderName               = request.TransferSenderName ?? string.Empty,
                    TransferApprovalStatus           = (Domain.Entities.TransferApprovalStatus?)request.TransferApprovalStatus,
                    TransferApprovalActionedOn       = request.TransferApprovalActionedOn
                });
            }
            catch (ValidationException ex)
            {
                _logger.Warn(ex, "Invalid request", accountId: request.EmployerAccountId, providerId: request.ProviderId, @event: request.Event);
                throw;
            }
            catch (Exception ex)
            {
                _logger.Error(ex, ex.Message);
                throw;
            }
        }
        public async Task CreateEvent(AccountEvent request)
        {
            try
            {
                _logger.Info($"Creating Account Event ({request.Event})", accountId: request.ResourceUri, @event: request.Event);

                await _mediator.SendAsync(new CreateAccountEventCommand
                {
                    Event       = request.Event,
                    ResourceUri = request.ResourceUri
                });
            }
            catch (ValidationException ex)
            {
                _logger.Warn(ex, "Invalid request", accountId: request.ResourceUri, @event: request.Event);
                throw;
            }
            catch (Exception ex)
            {
                _logger.Error(ex, ex.Message);
                throw;
            }
        }
        public async Task CreateEvent(AgreementEvent request)
        {
            try
            {
                _logger.Info($"Creating Agreement Event ({request.Event}), Contract: {request.ContractType}, Provider: {request.ProviderId}", providerId: request.ProviderId, @event: request.Event);

                await _mediator.SendAsync(new CreateAgreementEventCommand
                {
                    Event        = request.Event,
                    ProviderId   = request.ProviderId,
                    ContractType = request.ContractType
                });
            }
            catch (ValidationException ex)
            {
                _logger.Warn(ex, "Invalid request", providerId: request.ProviderId, @event: request.Event);
                throw;
            }
            catch (Exception ex)
            {
                _logger.Error(ex, ex.Message);
                throw;
            }
        }
Beispiel #7
0
        protected override async Task HandleCore(CreateGenericEventCommand command)
        {
            _logger.Info($"Creating Generic Event of type {command.Type}");

            _validator.ValidateAndThrow(command);

            var genericEvent = new GenericEvent
            {
                Type         = command.Type,
                Payload      = command.Payload,
                ResourceId   = command.ResourceId,
                ResourceType = command.ResourceType
            };

            try
            {
                await _repository.Create(genericEvent);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Error storing generic event in database");
                throw;
            }
        }