示例#1
0
        /// <summary>
        /// Returns a list of the pending requests associated with the authenticated user.
        /// </summary>
        /// <returns>HTML table containing a list of requests.</returns>
        public ActionResult AJAX_GetRequestTable()
        {
            string result = "<p>Could not authenticate the request.</p>\n";
            if (Request.IsAuthenticated) {

                DBAccessor dba = new DBAccessor();
                Person person = dba.GetPersonInformation(User.Identity.Name);

                if (person.permissions.coachEnabled) {
                    result = "";

                    // Call the database to get pending requests
                    List<Request> requests = dba.GetRequests(User.Identity.Name);

                    // Form an HTML table with the retrieved information
                    if (requests.Any()) {
                        result += "<table>\n";
                        result += "<tr><th>Request From</th><th>Requests to Join</th><th>Action</th></tr>\n";
                        foreach (Request request in requests) {
                            string playerName = request.requestee.firstName + " " + request.requestee.lastName;
                            result += "<tr><td>" + playerName + "</td><td>" + request.team.name + "</td>";
                            result += "<td><img src='./../Content/images/accept.png' height='20' width='20' class='request-action-image' alt='accept' onClick='action_acceptrequest(" + request.ID + ")' />";
                            result += "<img src='./../Content/images/decline.png' height='20' width='20' class='request-action-image' margin-right='5px' alt='decline' onClick='action_declinerequest(" + request.ID + ")' />";
                            result += "<div onClick='action_detailsrequest(" + request.ID + ")' class='request-action-text clickable-text'>Details</div></td></tr>";
                        }
                        result += "</table>\n";
                    }
                    else {
                        result += "<p>There are no pending requests at this time.</p>\n";
                    }
                }
                else {
                    result = "";
                }
            }

            return Json(
                new { message = result },
                JsonRequestBehavior.AllowGet
            );
        }
示例#2
0
        /// <summary>
        /// Adds a request entry to the database.
        /// </summary>
        /// <param name="teamID">The ID of the team being requested to join.</param>
        /// <returns>Success message of the request.</returns>
        public ActionResult AJAX_AddRequest(long teamID)
        {
            // Make sure the user is authenticated
            string result = "Request not authenticated.";

            if (Request.IsAuthenticated) {

                // Get the person id for the user currently logged in
                DBAccessor dba = new DBAccessor();
                long requesteeID = dba.GetPersonID(User.Identity.Name);

                // Get any previous requests to join the team
                List<Request> requests = dba.GetRequests(teamID, requesteeID);

                if (requests.Any()) {
                    result = "A request has already been sent.";
                }
                else {
                    // Add the request to the database
                    result = "Error making the request.";
                    if (dba.AddNewRequest(requesteeID, teamID)) {
                        result = "Request sent.";
                    }
                }
            }

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