/// <summary>
        /// Accepts the given invite to join a team. The player invited to join 
        /// the team is linked as a player of that team. The entry in the invites 
        /// table is then deleted.
        /// </summary>
        /// <param name="inviteID">The ID of the invite which was accepted.</param>
        /// <returns>The result of the accept.</returns>
        public ActionResult AJAX_AcceptInvite(long inviteID)
        {
            // Make sure the user is authenticated
            string result = "Request not authenticated.";

            if (Request.IsAuthenticated) {
                DBAccessor dba = new DBAccessor();

                // Get the invite from the database
                Invitation invite = dba.GetInvite(inviteID);

                // Get the current user's ID from the database
                long userID = dba.GetPersonID(User.Identity.Name);

                // Ensure the get invite call worked
                if (invite == null) {
                    result = "Error finding the invite in the database.";
                }
                else {
                    if (invite.invitee.Equals(User.Identity.Name)) {

                        // Link the player to the team
                        if (dba.AddPlayerToTeam(userID, invite.team.ID)) {

                            // Remove the invite entry from the database
                            if (dba.RemoveInvite(inviteID)) {
                                result = "You've been added to " + invite.team.name + " successfully.";

                                // Indicate the accept went through but the request wasn't removed
                            }
                            else {
                                result = "You've been added to " + invite.team.name + " but the invite wasn't removed.";
                            }

                            // If the link failed set an appropriate message
                        }
                        else {
                            result = "An error occured adding you to " + invite.team.name + ".";
                        }
                    }
                    else {
                        result = "Invalid attempt to accept an invite.";

                        LogEntry entry = new LogEntry(LogType.INVALID_REQUEST, LogFunction.ACCEPT_INVITE, LogAction.NA);
                        entry.User = new Person("NA", "NA", User.Identity.Name, "NA");
                        entry.Message = "Attempt to accept invite (ID " + invite.ID + ").";
                        dba.LogMessage(entry);
                    }
                }
            }

            // Return the success message of the accept
            return Json(
                new { message = result },
                JsonRequestBehavior.AllowGet
            );
        }
        /// <summary>
        /// Accepts the given request to join a team. The player that requested to 
        /// join the team is linked as a player of that team. The entry in the 
        /// request table is then deleted.
        /// </summary>
        /// <param name="requestID">The ID of the request which was accepted.</param>
        /// <returns>The result of the accept.</returns>
        public ActionResult AJAX_AcceptRequest(long requestID)
        {
            // Make sure the user is authenticated
            string result = "Request not authenticated.";

            if (Request.IsAuthenticated) {
                DBAccessor dba = new DBAccessor();

                // Get the player and team IDs from the database
                Request request = dba.GetRequest(requestID, RequestType.JOIN_TEAM);

                // Ensure the get request call worked
                if (request == null) {
                    result = "Error finding the request in the database.";

                } else {
                    Person user = new Person();
                    user.email = User.Identity.Name;
                    if (request.team.coaches.Contains(user, new PersonComparer())) {

                        // Link the player to the team
                        if (dba.AddPlayerToTeam(request.requestee.ID, request.team.ID)) {

                            // Remove the request entry from the database
                            long requesteeID = dba.GetPersonID(User.Identity.Name);
                            if (dba.RemoveRequest(requestID)) {
                                result = request.requestee.firstName + " " + request.requestee.lastName + " added to " + request.team.name + " successfully.";

                                // Indicate the accept went through but the request wasn't removed
                            }
                            else {
                                result = request.requestee.firstName + " " + request.requestee.lastName + " added to " + request.team.name + " but the request wasn't removed.";
                            }

                            // If the link failed set an appropriate message
                        }
                        else {
                            result = "Error adding " + request.requestee.firstName + " " + request.requestee.lastName + " to " + request.team.name;
                        }
                    }
                    else {
                        result = "Invalid attempt to accept request.";
                        String message = "Attempt to accept request from " + request.requestee.firstName + " " + request.requestee.lastName + " (ID " + request.requestee.ID + ") ";
                        message += "to join " + request.team.name + " (ID " + request.team.ID + ").";

                        LogEntry entry = new LogEntry(LogType.INVALID_REQUEST, LogFunction.ACCEPT_REQUEST_JOIN, LogAction.NA);
                        entry.User = user;
                        entry.Message = message;
                        dba.LogMessage(entry);
                    }
                }
            }

            // Return the success message of the accept
            return Json(
                new { message = result },
                JsonRequestBehavior.AllowGet
            );
        }