示例#1
0
        private PlayerNotificationData GetPlayerNotification(IDbConnection c, long idCreator, long idPlayer, long idTeam, bool wantsPin = false, long userId = -1)
        {
            var fromUser = UsersController.GetUserForId(c, idCreator);
            var toUser   = new User {
            };

            if (userId == -1) // User should exitst in current org
            {
                toUser = c.QueryFirst <User>($"SELECT u.id, u.name, u.mobile FROM users u JOIN players p ON p.idUser = u.id AND p.id = {idPlayer};");
                var userToGlobal = UsersController.GetUserForId(c, toUser.Id);
                toUser.Email          = userToGlobal.Email;
                toUser.EmailConfirmed = userToGlobal.EmailConfirmed;
            }
            else // Global User info
            {
                toUser = UsersController.GetUserForId(c, userId);
            }

            var mr = c.QueryMultiple(@"
                    SELECT id, name, logoImgUrl FROM organizations LIMIT 1;
                    SELECT id, name, logoImgUrl FROM teams WHERE id = @idTeam;
                ", new { idFrom = idCreator, idPlayer = idPlayer, idTeam = idTeam });

            // var fromUser = mr.ReadFirst<User>();
            // var toUser = mr.ReadFirst<User>();
            var org  = mr.ReadFirst <PublicOrganization>();
            var team = mr.ReadFirst <Team>();

            if (fromUser == null && idCreator >= 10000000)
            {
                fromUser = UsersController.GetGlobalAdminForId(idCreator);
            }

            if (team == null)
            {
                throw new Exception("Error.NotFound.Team");
            }
            if (toUser == null)
            {
                throw new Exception("Error.NotFound.ToUser");
            }
            if (fromUser == null)
            {
                throw new Exception("Error.NotFound.FromUser");
            }

            var activationLink = toUser.EmailConfirmed && !wantsPin ? "" : PlayersController.GetActivationLink(Request, mAuthTokenManager, toUser);
            var activationPin  = toUser.EmailConfirmed && !wantsPin ? "" : UsersController.GetActivationPin(mAuthTokenManager, toUser);

            return(new PlayerNotificationData
            {
                To = toUser,
                From = fromUser,
                Team = team,
                Org = org,
                ActivationLink = activationLink,
                ActivationPin = activationPin,
                Images = new PlayerInviteImages
                {
                    OrgLogo = Utils.GetUploadUrl(Request, org.LogoImgUrl, org.Id, "org"),
                    TeamLogo = Utils.GetUploadUrl(Request, team.LogoImgUrl, team.Id, "team")
                }
            });
        }