public async Task RevertUserAsync(Guid userId, Guid correlationId) { var domainEvents = await _domainEventStore.FindAllAsync(userId); var domainEventsToApply = domainEvents.Where(x => x.CorrelationId != correlationId); var getUserResult = await _userGetterService.GetByIdAsync(userId); getUserResult.Value.AddEvents(domainEventsToApply); getUserResult.Value.ApplyEvents(); await _userRepository.UpdateAsync(getUserResult.Value); }
public async Task HandleAsync(UserDeletionCompletedIntegrationEventFailure integrationEvent, CancellationToken cancellationToken) { var message = $"Could not finish {nameof(Account)} deletion process."; _logger.LogIntegrationEventError(ServiceComponentEnumeration.RivaIdentity, integrationEvent, "accountId={accountId}, message={message}, reason={reason}, code={code}", integrationEvent.UserId, message, integrationEvent.Reason, integrationEvent.Code); var accountDeletionCompletedIntegrationEventFailure = new AccountDeletionCompletedIntegrationEventFailure( integrationEvent.CorrelationId, integrationEvent.Code, integrationEvent.Reason, integrationEvent.UserId); var accountDeletionCompletedIntegrationEventFailureTask = _integrationEventBus.PublishIntegrationEventAsync(accountDeletionCompletedIntegrationEventFailure); try { var domainEvents = await _domainEventStore.FindAllAsync(integrationEvent.UserId); var accountCreatedDomainEvent = (AccountCreatedDomainEvent)domainEvents.First(x => x is AccountCreatedDomainEvent); var account = Account.Builder() .SetId(accountCreatedDomainEvent.AggregateId) .SetEmail(accountCreatedDomainEvent.Email) .SetConfirmed(accountCreatedDomainEvent.Confirmed) .SetPasswordHash(accountCreatedDomainEvent.PasswordHash) .SetSecurityStamp(accountCreatedDomainEvent.SecurityStamp) .SetCreated(accountCreatedDomainEvent.Created) .SetLastLogin(accountCreatedDomainEvent.LastLogin) .Build(); await _accountRepository.AddAsync(account); account.AddEvents(domainEvents); account.ApplyEvents(); await _accountRepository.UpdateAsync(account); } catch (Exception e) { _logger.LogIntegrationEventError(ServiceComponentEnumeration.RivaIdentity, integrationEvent, "userId={userId}, message={message}, stackTrace={stackTrace}", integrationEvent.UserId, e.Message, e.StackTrace); } await accountDeletionCompletedIntegrationEventFailureTask; }
public async Task HandleAsync(AnnouncementPreferencesDeletionCompletedIntegrationEventFailure integrationEvent, CancellationToken cancellationToken = default) { var message = $"Could not finish {nameof(User)} deletion process."; _logger.LogIntegrationEventError(ServiceComponentEnumeration.RivaUsers, integrationEvent, "userId={userId}, message={message}, reason={reason}, code={code}", integrationEvent.UserId, message, integrationEvent.Reason, integrationEvent.Code); var userDeletionCompletedIntegrationEventFailure = new UserDeletionCompletedIntegrationEventFailure( integrationEvent.CorrelationId, integrationEvent.Code, integrationEvent.Reason, integrationEvent.UserId); var userDeletionCompletedIntegrationEventFailureTask = _integrationEventBus.PublishIntegrationEventAsync(userDeletionCompletedIntegrationEventFailure); try { var domainEvents = await _domainEventStore.FindAllAsync(integrationEvent.UserId); var userCreatedDomainEvent = (UserCreatedDomainEvent)domainEvents.First(x => x is UserCreatedDomainEvent); var user = User.Builder() .SetId(integrationEvent.UserId) .SetEmail(userCreatedDomainEvent.Email) .SetServiceActive(userCreatedDomainEvent.ServiceActive) .SetAnnouncementPreferenceLimit(userCreatedDomainEvent.AnnouncementPreferenceLimit) .SetAnnouncementSendingFrequency(userCreatedDomainEvent.AnnouncementSendingFrequency) .Build(); await _userRepository.AddAsync(user); user.AddEvents(domainEvents); user.ApplyEvents(); await _userRepository.UpdateAsync(user); } catch (Exception e) { _logger.LogIntegrationEventError(ServiceComponentEnumeration.RivaUsers, integrationEvent, "userId={userId}, message={message}, stackTrace={stackTrace}", integrationEvent.UserId, e.Message, e.StackTrace); } await userDeletionCompletedIntegrationEventFailureTask; }