Beispiel #1
0
        private static object AfterCreateSanction(IDbConnection c, IDbTransaction t, Sanction value, long idCreator)
        {
            // Insert the first allegation
            var newAllegation = new SanctionAllegation
            {
                Content    = value.InitialContent,
                IdSanction = value.Id,
                IdUser     = idCreator,
                Date       = DateTime.Now,
                Status     = (int)SanctionAllegationStatus.Created,
                //Title = Localization.Get("Resolución comité de competición", null),
                Title   = Translation.Get("FirstSanctionAllegationTitle"),
                Visible = true
            };

            c.Insert(newAllegation, t);

            if (value.Type == (int)SanctionType.Team)
            {
                // Apply penalty for team: tournament points
                // MatchEvent.CreateTeamSanctionPenalty(c, t, value); // 🚧TODO: Migrate duplicate functions to matchEvent*
                CreateTeamSanctionPenalty(c, t, value);
                FillSanctionTeam(c, t, value);
            }
            // Check Tournament Flags
            else
            {
                // Create sanction matches for this sanction
                CreatePlayerSanctionMatches(c, t, value);
                FillSanctionTeamAndPlayer(c, t, value);


                var tournament = c.Get <Tournament>(value.IdTournament);
                if (!string.IsNullOrEmpty(tournament.NotificationFlags))
                {
                    try
                    {
                        JObject notificationFlags = JsonConvert.DeserializeObject <JObject>(tournament.NotificationFlags);

                        if (notificationFlags["notifySanction"] != null && (bool)notificationFlags["notifySanction"] == true)
                        {
                            // Notify push to player
                            var playerIdUser = c.ExecuteScalar <long>("SELECT idUser FROM players WHERE id = @id", new { id = value.IdPlayer });

                            //NotificationsController.TryNotifyUser(c, t, playerIdUser, Localization.Get("Nueva sanción", null), Localization.Get("Se te ha sancionado con {0} partidos.", null, value.NumMatches));
                            NotificationsController.TryNotifyUser(c, t, playerIdUser, "Nueva sanción", $"Se te ha sancionado con {value.NumMatches}");
                        }
                    } catch { }
                }
            }

            return(value);
        }
Beispiel #2
0
        private void NotifyPlayer(IDbConnection c, IDbTransaction t, long playerId, string title, string message)
        {
            Audit.Information(this, "{0}: Notifications.NotifyPlayer: {1} | {2}", GetUserId(), title, message); // LOG

            var player = c.QueryFirst <Player>($"SELECT * FROM players WHERE id = {playerId}");

            // 🔎 Multiple devices
            int notificationsNumber = NotificationsController.NotifyUser(c, null, player.IdUser, title, message);

            c.Insert(new Notification {
                IdCreator = GetUserId(), IdRcptUser = player.IdUser, Status = (int)NotificationStatus.Unread, Text = message, Text2 = title, TimeStamp = DateTime.Now
            });
        }
Beispiel #3
0
        private void NotifyPlayer(IDbConnection c, IDbTransaction t, long playerId, string title, string message)
        {
            Audit.Information(this, "{0}: Notifications.NotifyPlayer: {1} | {2}", GetUserId(), title, message);

            var player = c.Get <Player>(playerId);

            if (player.IdUser != 0)
            {
                var users = c.Query <User>("SELECT devicetoken FROM users u JOIN userdevices ud ON ud.idUser = u.id WHERE u.id = @id", new { id = player.IdUser });
                if (users.Count() > 0)
                {
                    int usersNotified = NotificationsController.NotifyUsers(users, title, message);
                }
            }

            c.Insert(new Notification {
                IdCreator = GetUserId(), IdRcptUser = player.IdUser, Status = (int)NotificationStatus.Unread, Text = message, Text2 = title, TimeStamp = DateTime.Now
            });
        }