예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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();
            }
        }
예제 #4
0
 protected void When(UserUpdatedIntegrationEvent @event)
 {
     Id       = @event.AggregateRootId;
     Username = @event.Username;
     Email    = @event.Email;
 }
예제 #5
0
 public void UpdateEmail(string email)
 {
     Raise(UserUpdatedIntegrationEvent.Create(this, Username, email));
 }
예제 #6
0
 public void UpdateUsername(string username)
 {
     Raise(UserUpdatedIntegrationEvent.Create(this, username, Email));
 }
예제 #7
0
 protected void When(UserUpdatedIntegrationEvent @event)
 {
     Username = @event.Username;
     Email    = @event.Email;
 }