Beispiel #1
0
        public virtual ActionResult InvitePlayer(PlayerInvitationViewModel playerInvitationViewModel, ApplicationUser currentUser)
        {
            PlayerInvitation playerInvitation = new PlayerInvitation
            {
                InvitedPlayerId    = playerInvitationViewModel.PlayerId,
                InvitedPlayerEmail = playerInvitationViewModel.EmailAddress.Trim(),
                EmailSubject       = playerInvitationViewModel.EmailSubject,
                CustomEmailMessage = playerInvitationViewModel.EmailBody
            };

            playerInviter.InvitePlayer(playerInvitation, currentUser);

            return(new RedirectResult(Url.Action(MVC.GamingGroup.ActionNames.Index, MVC.GamingGroup.Name)));
        }
Beispiel #2
0
        public virtual ActionResult InvitePlayer(PlayerInvitationViewModel playerInvitationViewModel, ApplicationUser currentUser)
        {
            var playerInvitation = new PlayerInvitation
            {
                InvitedPlayerId    = playerInvitationViewModel.PlayerId,
                InvitedPlayerEmail = playerInvitationViewModel.EmailAddress.Trim(),
                EmailSubject       = playerInvitationViewModel.EmailSubject,
                CustomEmailMessage = playerInvitationViewModel.EmailBody
            };

            playerInviter.InvitePlayer(playerInvitation, currentUser);

            SetToastMessage(TempMessageKeys.TEMP_MESSAGE_KEY_PLAYER_INVITED, $"Mail to invite {playerInvitationViewModel.PlayerName} sended succesfully");

            return(new RedirectResult(Url.Action(MVC.GamingGroup.ActionNames.Index, MVC.GamingGroup.Name)));
        }
Beispiel #3
0
        public Player CreatePlayer(CreatePlayerRequest createPlayerRequest, ApplicationUser applicationUser, bool linkCurrentUserToThisPlayer = false)
        {
            ValidateRequestIsNotNull(createPlayerRequest);
            ValidatePlayerNameIsNotNullOrWhiteSpace(createPlayerRequest.Name);
            ValidateRequestedEmailIsntSetAtTheSameTimeAsAttemptingToLinktoCurrentPlayer(createPlayerRequest,
                                                                                        linkCurrentUserToThisPlayer);
            var gamingGroupId = ValidateAndGetGamingGroupId(createPlayerRequest.GamingGroupId, applicationUser);

            ValidatePlayerDoesntExistWithThisName(createPlayerRequest.Name, gamingGroupId);

            ValidateUserNotAlreadyRegisteredWithThisEmail(
                gamingGroupId, createPlayerRequest.PlayerEmailAddress);

            var newPlayer = new Player
            {
                Name              = createPlayerRequest.Name,
                Active            = true,
                ApplicationUserId = linkCurrentUserToThisPlayer ? applicationUser.Id : null,
                GamingGroupId     = gamingGroupId
            };

            newPlayer = _dataContext.Save(newPlayer, applicationUser);

            if (!string.IsNullOrWhiteSpace(createPlayerRequest.PlayerEmailAddress))
            {
                var playerInvitation = new PlayerInvitation
                {
                    EmailSubject       = $"NemeStats Invitation from {applicationUser.UserName}",
                    InvitedPlayerEmail = createPlayerRequest.PlayerEmailAddress,
                    InvitedPlayerId    = newPlayer.Id,
                    GamingGroupId      = gamingGroupId
                };
                _playerInviter.InvitePlayer(playerInvitation, applicationUser);
            }

            _dataContext.CommitAllChanges();

            new Task(() => _eventTracker.TrackPlayerCreation(applicationUser)).Start();

            return(newPlayer);
        }