Example #1
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 }));
        }
Example #2
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));
        }
Example #3
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());
            }
        }