public async Task HandleDrinkEventsAsync(Activity activity, User currentUser)
        {
            if (activity.Drink.DrinkType == DrinkType.Anti)
            {
                return;
            }
            var drinkEvent = await drinkEventRepository.FindCurrentDrinkEventAsync();

            if (drinkEvent == null)
            {
                return;
            }

            if (!drinkEvent.AddScoringUserId(currentUser.Id))
            {
                return;
            }

            await drinkEventRepository.UpdateDrinkEventAsync(drinkEvent);

            await rankingService.IncreaseScoreAsync(currentUser.Id, Constants.Scores.StandardDrinkAction);

            string message = await translationService.GetTranslationAsync(currentUser.Language, "DrinkEventActivityWinMessage", Constants.Scores.StandardDrinkAction);

            var drinkEventNotificationActivity = Activity.CreateNotificationActivity(currentUser.Id, currentUser.Name, message);
            await activityRepository.AddActivityAsync(drinkEventNotificationActivity.ToEntity());

            var notifications = new[] { new DrinkEventCongratulationNotification(currentUser.Id) };
            await pushNotificationService.NotifyAsync(notifications);
        }
Exemple #2
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);
        }
Exemple #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);
        }