public async Task <string> Handle(AddMessageActivityCommand request, CancellationToken cancellationToken) { var user = await this.userRepository.GetUserAsync(request.UserId); var activity = Domain.Activity.CreateMessageActivity(request.Location, request.UserId, user.Name, request.Message, request.Venue?.ToDomain()); var savedActivity = await this.activityRepository.AddActivityAsync(activity.ToEntity()); await activityRepository.AddToActivityAddedTopicAsync(savedActivity.Id); return(savedActivity.Id); }
private async Task AddVenueActivityAsync(AddVenueActivityDTO venueActivity) { var user = await this.userRepository.GetUserAsync(venueActivity.UserId); var activity = Activity.Domain.Activity.CreateVenueActivity( venueActivity.UserId, user.Name, venueActivity.Venue.ToDomain(), venueActivity.Action); var savedActivity = await this.activityRepository.AddActivityAsync(activity.ToEntity()); await activityRepository.AddToActivityAddedTopicAsync(savedActivity.Id); }
public async Task <string> Handle(AddDrinkActivityCommand request, CancellationToken cancellationToken) { var user = await this.userRepository.GetUserAsync(request.UserId); var activity = Domain.Activity.CreateDrinkActivity(request.Location, request.UserId, user.Name, request.DrinkType, request.DrinkId, request.DrinkName, request.AlcPrc, request.Volume, request.Venue?.ToDomain()); var savedActivity = await this.activityRepository.AddActivityAsync(activity.ToEntity()); await activityRepository.AddToActivityAddedTopicAsync(savedActivity.Id); await messagingService.SendMessageAsync(new DrinkEventMessage(request.UserId, request.DrinkId, activity.Timestamp)); return(savedActivity.Id); }
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); }
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); }
private async void OnGameEnded(object sender, GameEndedEventArgs e) { e.Game.GameEnded -= this.OnGameEnded; await this.notificationService.SendSignalRMessageAsync( e.Game.PlayerUserIds, Constants.SignalR.NotificationHubName, HubMethodNames.GameEnded, new GameEndedMessage(e.Game.Id, e.WinnerUserId)); var users = await this.userRepository.SearchUsersAsync(e.Game.PlayerUserIds); var pushInfos = users.Where(u => u.PushInfo != null).Select(u => new { u.Language, u.PushInfo }); var winnerUser = users.FirstOrDefault(u => u.Id == e.WinnerUserId); string url = $"{Constants.Urls.ApplicationUrl}/game/end/{e.Game.Id}"; var messagesPerLanguage = pushInfos.GroupBy(g => g.Language); foreach (var lang in messagesPerLanguage) { var gameOverTitle = await this.translationService.GetTranslationAsync(lang.Key, "Game.GameOver"); var gameOverMessage = winnerUser != null ? await translationService.GetTranslationAsync(lang.Key, "Game.WinnerMessage", winnerUser.Name) : await translationService.GetTranslationAsync(lang.Key, "Game.NoWinnerMessage"); var languagePushInfos = lang.Select(l => l.PushInfo).ToList(); this.notificationService.SendWebPushMessage(languagePushInfos, new WebPushNotificationMessage(gameOverMessage, gameOverTitle, url)); } var activity = Activity.Domain.Activity.CreateGameActivity(e.Game.ToEntity(users.Select(u => u.ToUserInfo())), winnerUser?.ToUserInfo()); var savedActivity = await this.activityRepository.AddActivityAsync(activity.ToEntity()); await activityRepository.AddToActivityAddedTopicAsync(savedActivity.Id); }