private async Task <IActionResult> CreateGameEventParticipationForGroup( GameEventDto gameEvent, string groupName, IEnumerable <string> users, SendGameEventInvitationDto.GameEventLinkGenerator gameEventLinkGenerator) { try { await _gameEventParticipationService.CreateGameEventParticipationsIgnoringErrorsAsync( gameEvent.Id, gameEventLinkGenerator, users); } catch (ApplicationException exception) { return(Error.FromController(this).ErrorJson("Error!", exception.Message, HttpStatusCode.BadRequest)); } catch { return(Error.FromController(this).ErrorJson( "Error!", "An unexpected error has occured while processing your request.", HttpStatusCode.InternalServerError)); } return(Ok( new { title = "Invite sent.", message = $"An email with your invitation to the {gameEvent.Name} event has been sent to {groupName}." })); }
private async Task SendGameEventInvitationsAsync( int gameEventId, [NotNull] IEnumerable <ApplicationUser> usersTo, SendGameEventInvitationDto.GameEventLinkGenerator gameEventLinkGenerator) { var gameEventData = await _repository.GameEvents .Where(g => g.Id == gameEventId) .Include(g => g.Participations) .ThenInclude(p => p.Participant) .Select( g => new { g.Id, g.Name, CreatorParticipations = g.Participations .Where(p => p.ParticipationStatus == ParticipationStatus.Creator) }).SingleAsync(); var creatorName = gameEventData.CreatorParticipations.Single().Participant.UserName; var notifications = usersTo.Select( u => new GameEventInvitationNotification( gameEventData.Name, creatorName, u.UserName, u.Email, gameEventLinkGenerator(gameEventId.ToString()))); await _notificationService.CreateNotificationBatch(notifications).SendAsync(); }
public async Task CreateGameEventParticipationsIgnoringErrorsAsync( int gameEventId, SendGameEventInvitationDto.GameEventLinkGenerator gameEventLinkGenerator, IEnumerable <string> users) { var usersAlreadyInvitedForEvent = await GetUserNamesOfUsersInvitedForGameEvent(gameEventId); var userNamesOfUsersToInvite = users.Where(u => !usersAlreadyInvitedForEvent.Contains(u)).ToList(); var usersToInvite = await _repository.ApplicationUsers .Where(u => userNamesOfUsersToInvite.Contains(u.UserName)).ToListAsync(); using (var transaction = _repository.BeginTransaction()) { await CreateNewGameEventParticipations(gameEventId, usersToInvite.Select(u => u.Id)); await SendGameEventInvitationsAsync( gameEventId, usersToInvite, gameEventLinkGenerator); transaction.Commit(); } }
private Task SendGameEventInvitationAsync( int gameEventId, [NotNull] ApplicationUser userTo, SendGameEventInvitationDto.GameEventLinkGenerator gameEventLinkGenerator) => SendGameEventInvitationsAsync(gameEventId, new[] { userTo }, gameEventLinkGenerator);