Beispiel #1
0
        public async Task <Unit> Handle(UpdateUserProfileImageCommand request, CancellationToken cancellationToken)
        {
            var user = await this.userRepository.GetUserAsync(request.UserId);

            using (var stream = request.Image.OpenReadStream())
            {
                await storageAccessService.SaveFileInBlobStorage(ContainerNames.ProfileImages, request.UserId, stream);

                var activity = Activity.Domain.Activity.CreateProfileImageUpdateActivity(request.UserId, user.Name);
                await activityRepository.AddActivityAsync(activity.ToEntity());
            }
            return(Unit.Value);
        }
        public async Task <string> Handle(AddImageActivityCommand request, CancellationToken cancellationToken)
        {
            var user = await this.userRepository.GetUserAsync(request.UserId);

            // store file in blob storage
            string imageUrlOriginal = await storageAccessService.SaveFileInBlobStorage("img", "activities", request.FileName, request.Stream);

            var activity = Domain.Activity.CreateImageActivity(request.Location, request.UserId, user.Name, imageUrlOriginal);

            var savedActivity = await this.activityRepository.AddActivityAsync(activity.ToEntity());

            await activityRepository.AddToActivityAddedTopicAsync(activity.Id);

            return(savedActivity.Id);
        }
Beispiel #3
0
        public async Task <Unit> Handle(CreateOrUpdateUserCommand request, CancellationToken cancellationToken)
        {
            var result = await this.userRepository.CreateOrUpdateUserAsync(request);

            if (result.IsNewUser)
            {
                await this.drinkRepository.CreateDefaultDrinksForUserAsync(request.UserId);

                if (!string.IsNullOrEmpty(request.ProfileImageUrl))
                {
                    var httpClient = this.httpClientFactory.CreateClient();
                    using (var profileImageStream = await httpClient.GetStreamAsync(request.ProfileImageUrl))
                    {
                        await storageAccessService.SaveFileInBlobStorage(ContainerNames.ProfileImages, request.UserId, profileImageStream);
                    }
                }

                var activity = Activity.Domain.Activity.CreateRegistrationActivity(request.UserId, request.Name);

                await activityRepository.AddActivityAsync(activity.ToEntity());

                await activityRepository.AddToPersonalizedFeedAsync(request.UserId, activity.ToEntity());

                await activityRepository.AddToActivityAddedTopicAsync(activity.Id);
            }

            if (result.NameHasChanged)
            {
                var activity = Activity.Domain.Activity.CreateRenameActivity(request.UserId, request.Name, result.OriginalUserName);
                await activityRepository.AddActivityAsync(activity.ToEntity());

                var renameMessage = new UserRenamedMessage(request.UserId, result.OriginalUserName, request.Name);
                await storageAccessService.AddQueueMessage(QueueNames.UserRenamed, renameMessage);
            }

            return(Unit.Value);
        }