public async Task <Result> UpdateAsync(string id, UserUpdateModel model) { var user = await _context.Set <User>() .SingleOrDefaultAsync(u => u.Id == id); if (user is null) { var error = Errors.UserNotFound(id); return(Result.Failure(error)); } if (user.Name != model.Name) { user.Name = model.Name; var tagResult = await _tagGeneratorService.GenerateAsync(id, model.Name); if (!tagResult.Succeeded) { return(Result.Failure(tagResult.Errors)); } user.Tag = tagResult.Data; } var userUpdatedEvent = new UserUpdatedIntegrationEvent(id, user.Name, user.Tag); await _integrationEventService.SaveEventsAndUsersContextChangesAsync(userUpdatedEvent); await _integrationEventService.PublishThroughEventBusAsync(userUpdatedEvent); return(Result.Success); }
public async Task HandleAsync(UpdateUserCommand command, CancellationToken cancellationToken = default) { var getUserResult = await _userGetterService.GetByIdAsync(command.UserId); if (!getUserResult.Success) { throw new ResourceNotFoundException(getUserResult.Errors); } UpdateAnnouncementPreferenceLimit(getUserResult.Value, command.AnnouncementPreferenceLimit, command.CorrelationId); UpdateAnnouncementSendingFrequency(getUserResult.Value, command.AnnouncementSendingFrequency, command.CorrelationId); getUserResult.Value.ChangeServiceActive(command.ServiceActive, command.CorrelationId); if (command.Picture != null && command.Picture.Data.Any()) { var pictureUrl = await _blobContainerService.UploadFileAsync(command.Picture.Data, $"image-{getUserResult.Value.Id.ToString().ToLower()}", command.Picture.ContentType); getUserResult.Value.ChangePicture(pictureUrl, command.CorrelationId); } await _communicationBus.DispatchDomainEventsAsync(getUserResult.Value, cancellationToken); await _userRepository.UpdateAsync(getUserResult.Value); var userUpdatedIntegrationEvent = new UserUpdatedIntegrationEvent(command.CorrelationId, getUserResult.Value.Id, getUserResult.Value.ServiceActive, getUserResult.Value.AnnouncementSendingFrequency.ConvertToEnum()); await _integrationEventBus.PublishIntegrationEventAsync(userUpdatedIntegrationEvent); }
public async Task UpdateAsync(UserUpdatedIntegrationEvent integrationEvent) { var flatForRentAnnouncementPreferences = await _cosmosStore.Query().Where(x => x.UserId == integrationEvent.UserId).ToListAsync(); foreach (var flatForRentAnnouncementPreference in flatForRentAnnouncementPreferences) { flatForRentAnnouncementPreference.ServiceActive = integrationEvent.ServiceActive; flatForRentAnnouncementPreference.AnnouncementSendingFrequency = integrationEvent.AnnouncementSendingFrequency; } var updateResult = await _cosmosStore.UpdateRangeAsync(flatForRentAnnouncementPreferences); if (!updateResult.IsSuccess) { throw new UpdateManyFailureException(); } }
protected void When(UserUpdatedIntegrationEvent @event) { Id = @event.AggregateRootId; Username = @event.Username; Email = @event.Email; }
public void UpdateEmail(string email) { Raise(UserUpdatedIntegrationEvent.Create(this, Username, email)); }
public void UpdateUsername(string username) { Raise(UserUpdatedIntegrationEvent.Create(this, username, Email)); }
protected void When(UserUpdatedIntegrationEvent @event) { Username = @event.Username; Email = @event.Email; }