public ActionResult LadderRequests_Reject([DataSourceRequest] DataSourceRequest request, LadderJoinViewModel model)
        {
            // for rejecting a players request to join a ladder
            if (model != null && ModelState.IsValid)
            {
                Users.User user = Users.User.Load(model.UserId);
                Ladder ladder = Ladder.Load(model.LadderId);

                user.Requests.Remove(ladder);
                ladder.Requests.Remove(user);

                user.Save();
                ladder.Save();
                // email notification
                var email = new NewNotificationEmail
                {
                    To = user.Email,
                    FirstName = user.FirstName,
                    NotificationMessage = ("Sorry, your request to join " + ladder.Name + " ladder has been declined!")
                };

                email.Send();
            }
            return Json(new[] { model }.ToDataSourceResult(request, ModelState));
        }
        public ActionResult PlayerRequests_Accept([DataSourceRequest] DataSourceRequest request, PlayerRequestViewModel model)
        {
            // for accepting a player request
            if (model != null && ModelState.IsValid)
            {
                Users.User user = Users.User.Load(model.Id);
                user.PlayerRating = PlayerRatingCollection.LoadAll().Where(r => r.Rating == model.Rating).First();
                user.Save();
                // sends automated email
                var email = new NewNotificationEmail
                {
                    To = user.Email,
                    FirstName = user.FirstName,
                    NotificationMessage = "You have been approved to become a Player. Congratulations!"
                };

                email.Send();
            }

            return Json(new[] { model }.ToDataSourceResult(request, ModelState));
        }
        public ActionResult LadderRequests_Accept(int ladderId, int userId)
        {
            // for accepting a players request to join a ladder
            if (userId > 0 && ladderId > 0) //0 is default if there is null passed for some reason
            {
                Users.User user = Users.User.Load(userId);
                Ladder ladder = Ladder.Load(ladderId);

                LadderPlayer ladderPlayer = new LadderPlayer();
                ladderPlayer.LadderId = ladderId;
                ladderPlayer.PlayerId = userId;
                ladderPlayer.ChallengesLost = 0;
                ladderPlayer.ChallengesWon = 0;
                ladderPlayer.DateAdded = DateTime.UtcNow;
                ladderPlayer.PreviousPoints = 0;
                ladderPlayer.PlayerPoints = LadderPointsCollection.LoadByLadder(ladder)
                                                .Where(p => p.RatingId == user.PlayerRatingId)
                                                .FirstOrDefault()
                                                .NumStartingPoints;
                ladderPlayer.Save();

                UpdateRankings(ladder);

                user.Requests.Remove(ladder);
                ladder.Requests.Remove(user);

                user.Save();
                ladder.Save();

                // email notification
                var email = new NewNotificationEmail
                {
                    To = user.Email,
                    FirstName = user.FirstName,
                    NotificationMessage = ("Congratulations, your request to join " + ladder.Name + " ladder has been Accepted!")
                };

                email.Send();

                return RedirectToAction("Home", "Admin");
            }
            return RedirectToAction("Home", "Admin");
        }