Ejemplo n.º 1
0
        public ActionResult Add(NotificationsForm frm)
        {
            if (!ModelState.IsValid)
            {
                return(Content("Error"));
            }

            if (frm.SeasonId != null)
            {
                switch (frm.RelevantEntityLogicalName)
                {
                case LogicaName.Team:
                    notesRep.SendToTeam(frm.SeasonId.Value, frm.EntityId, frm.Message);
                    break;

                case  LogicaName.League:
                    notesRep.SendToLeague(frm.SeasonId.Value, frm.EntityId, frm.Message);
                    break;

                case LogicaName.Union:
                    notesRep.SendToUnion(frm.SeasonId.Value, frm.EntityId, frm.Message);
                    break;

                case LogicaName.Club:
                    //notesRep.SendToClub(frm.SeasonId.Value, frm.EntityId, frm.Message);
                    break;
                }
            }

            var notsServ = new GamesNotificationsService();

            notsServ.SendPushToDevices(GlobVars.IsTest);

            return(RedirectToAction("List", new { entityId = frm.EntityId, logicalName = frm.RelevantEntityLogicalName }));
        }
Ejemplo n.º 2
0
        public ActionResult UpdateGame(GameCycleForm frm)
        {
            try
            {
                bool isChanged = false;
                var  gc        = gamesRepo.GetGameCycleById(frm.CycleId);
                if (gc.AuditoriumId != frm.AuditoriumId)
                {
                    isChanged       = true;
                    gc.AuditoriumId = frm.AuditoriumId;
                }
                gc.RefereeId = frm.RefereeId;
                if (!gc.StartDate.Equals(frm.StartDate))
                {
                    isChanged    = true;
                    gc.StartDate = frm.StartDate;
                }

                //  Teams could be replaced only before game starts
                if (gc.GameStatus != GameStatus.Started && gc.GameStatus != GameStatus.Ended && gc.Group.TypeId == 1)
                {
                    gc.HomeTeamId  = frm.HomeTeamId;
                    gc.GuestTeamId = frm.GuestTeamId;
                }
                gamesRepo.Update(gc);

                if (isChanged && gc.IsPublished)
                {
                    NotesMessagesRepo notesRep = new NotesMessagesRepo();
                    if (gc.Stage != null && gc.Stage.League != null && gc.Stage.League.SeasonId != null)
                    {
                        String message = String.Format("Game details has been updated: {0} vs {1}", gc.HomeTeam != null ? gc.HomeTeam.Title : "", gc.GuestTeam != null ? gc.GuestTeam.Title : "");

                        if (gc.HomeTeamId != null)
                        {
                            notesRep.SendToTeam((int)gc.Stage.League.SeasonId, (int)gc.HomeTeamId, message);
                        }
                        if (gc.GuestTeamId != null)
                        {
                            notesRep.SendToTeam((int)gc.Stage.League.SeasonId, (int)gc.GuestTeamId, message);
                        }
                        if (gc.RefereeId != null)
                        {
                            notesRep.SendToUsers(new List <int> {
                                (int)gc.RefereeId
                            }, message);
                        }
                    }

                    var notsServ = new GamesNotificationsService();
                    notsServ.SendPushToDevices(GlobVars.IsTest);
                }
            }
            catch (System.Exception e)
            {
                return(Json(new { stat = "error", message = e.ToString() }));
            }
            return(Json(new { stat = "ok", id = frm.CycleId }));
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> PostDeleteToken(TokenItem item)
        {
            var notifyService = new GamesNotificationsService();

            await notifyService.UnregisterDeviceToken(base.CurrUserId, item.Token);

            return(Ok());
        }
Ejemplo n.º 4
0
        public async Task <IHttpActionResult> PostSaveToken(TokenItem item)
        {
            var notifyService = new GamesNotificationsService();
            int id            = 0;

            await notifyService.SaveUserDeviceToken(CurrUserId, item.Token, id, item.IsIOS, item.Section);

            return(Ok());
        }
Ejemplo n.º 5
0
        public IHttpActionResult GetGamesTimes()
        {
            var gnServ = new GamesNotificationsService();

            gnServ.SaveNotifications();

            gnServ.SendPushToDevices(Settings.IsTest);

            return(Ok());
        }
Ejemplo n.º 6
0
        public ActionResult UpdateGame(GamesCycle gc)
        {
            GamesCycle editGc = gamesRepo.GetGameCycleById(gc.CycleId);

            try
            {
                bool isChanged = false;
                if (gc.AuditoriumId != editGc.AuditoriumId)
                {
                    isChanged           = true;
                    editGc.AuditoriumId = gc.AuditoriumId;
                }
                editGc.RefereeId = gc.RefereeId;
                if (!editGc.StartDate.Equals(gc.StartDate))
                {
                    isChanged        = true;
                    editGc.StartDate = gc.StartDate;
                }

                gamesRepo.Update(editGc);
                TempData["SavedId"] = editGc.CycleId;

                if (isChanged && editGc.IsPublished)
                {
                    NotesMessagesRepo notesRep = new NotesMessagesRepo();
                    if (editGc.Stage != null && editGc.Stage.League != null && editGc.Stage.League.SeasonId != null)
                    {
                        String message = String.Format("Game details has been updated: {0} vs {1}", editGc.HomeTeam != null ? editGc.HomeTeam.Title : "", editGc.GuestTeam != null ? editGc.GuestTeam.Title : "");

                        if (editGc.HomeTeamId != null)
                        {
                            notesRep.SendToTeam((int)editGc.Stage.League.SeasonId, (int)editGc.HomeTeamId, message);
                        }
                        if (editGc.GuestTeamId != null)
                        {
                            notesRep.SendToTeam((int)editGc.Stage.League.SeasonId, (int)editGc.GuestTeamId, message);
                        }
                        if (gc.RefereeId != null)
                        {
                            notesRep.SendToUsers(new List <int> {
                                (int)editGc.RefereeId
                            }, message);
                        }
                    }

                    var notsServ = new GamesNotificationsService();
                    notsServ.SendPushToDevices(GlobVars.IsTest);
                }
            } catch (Exception e) { }
            return(RedirectToAction("Game", editGc));
        }
Ejemplo n.º 7
0
        public async Task <IHttpActionResult> PostFriendRequest(int friendId)
        {
            User user = CurrentUser;

            if (user == null)
            {
                return(NotFound());
            }

            if (!db.Users.Any(u => u.UserId == friendId && u.IsArchive == false && u.IsActive == true))
            {
                return(NotFound());
            }

            if (AreFriends(user.UserId, friendId))
            {
                return(BadRequest("Users are already friend or a friend request already sent."));
            }

            int recoredscount = FriendsService.CreateFriendRequest(user.UserId, friendId);

            if (recoredscount == 1)
            {
                // send notification to the user (who is being requested for friendship)
                var message = "קיבלת בקשת חברות";// "You have received a friendship request";
                NotesMessagesRepo msgRepo = new NotesMessagesRepo();
                msgRepo.SendToUsers(new List <int>()
                {
                    friendId
                }, message, (MessageTypeEnum.PushNotifyOnly | MessageTypeEnum.Root));
                GamesNotificationsService gns = new GamesNotificationsService();
                await gns.SendPushToDevices(false);

                return(Ok());
            }
            else
            {
                return(InternalServerError());
            }
        }