예제 #1
0
        public ActionResult AcceptCoachRequest(long requestID)
        {
            String result = "Coach permission added.";
            DBAccessor dba = new DBAccessor();
            Request request = dba.GetRequest(requestID, RequestType.COACH_PERMISSION);

            if (request != null) {
                if (dba.AddCoachPermission(request.requestee.ID)) {
                    // Form an email
                    MailMessage newMessage = new MailMessage();
                    SmtpClient mailService = new SmtpClient();

                    //set the addresses
                    newMessage.From = new MailAddress(AppConstants.EMAIL_ADMIN);
                    newMessage.To.Add(request.requestee.email);

                    //set the content
                    newMessage.Subject = "Coach Permission Approved";
                    newMessage.Body = "Your request to receive coach permission at dugoutdigits.com has been approved.";

                    //send the message
                    mailService.UseDefaultCredentials = false;
                    mailService.DeliveryMethod = SmtpDeliveryMethod.Network;
                    mailService.Host = AppConstants.EMAIL_SMTP_ADDRESS;
                    mailService.Credentials = new NetworkCredential(AppConstants.EMAIL_SMTP_USERNAME, AppConstants.EMAIL_SMTP_PASSWORD);
                    mailService.Send(newMessage);

                    // Remove the request from the DB
                    if (!dba.RemoveRequest(request.ID)) {
                        result = "Error removing the coach request from the database (ID=" + request.ID + ").";
                    }
                }
                else {
                    result = "Error adding coach permission.";
                }
            }
            else {
                result = "The request couldn't be found in the database.";
            }

            return Json(
                new { message = result },
                JsonRequestBehavior.AllowGet
            );
        }
예제 #2
0
        /// <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
            );
        }
예제 #3
0
        /// <summary>
        /// Returns the details for a single request denoted by the given request ID.
        /// </summary>
        /// <param name="requestID">The ID of the request in interest.</param>
        /// <returns>Returns an HTML format with the details of the request.</returns>
        public ActionResult AJAX_GetRequest(long requestID)
        {
            string result = "<p>Could not authenticate the request.</p>\n";
            if (Request.IsAuthenticated) {

                DBAccessor dba = new DBAccessor();
                Request request = dba.GetRequest(requestID, RequestType.JOIN_TEAM);

                if (request != null) {
                    // Form the player information
                    result = "<div class='lightbox-content-close clickable-text' onclick='action_hidedetails()'>Close</div>";
                    result += "<h3>Pending Request</h3>\n";
                    result += "<div id='request-details-left'>\n<img src='" + request.requestee.imageURL + "' alt='player picture' />\n</div>\n";
                    result += "<div id='request-details-right'>\n";
                    result += "<p>" + request.requestee.firstName + " " + request.requestee.lastName + "</p>\n";
                    result += "<p>" + request.requestee.email + "</p>\n";
                    result += "<p> Requests to join the " + request.team.name + "</p>\n";
                    result += "<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>\n";
                }
                else {
                    result = "<div class='lightbox-content-close clickable-text' onclick='action_hidedetails()'>Close</div>";
                    result += "<h3>Oops</h3>\n";
                    result += "<p>Something went wrong retrieving the details of the request.</p>";
                    result += "</div>\n";
                }
            }

            return Json(
                new { message = result },
                JsonRequestBehavior.AllowGet
            );
        }
예제 #4
0
        /// <summary>
        /// Removes a request entry from the database.
        /// </summary>
        /// <param name="requestID">The ID of the request entry to remove.</param>
        /// <returns>Success message of the request removal.</returns>
        public ActionResult AJAX_RemoveRequest(long requestID)
        {
            // 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();
                Person requestee = dba.GetPersonInformation(User.Identity.Name);

                // Get the request that's trying to be removed
                Request request = dba.GetRequest(requestID, RequestType.JOIN_TEAM);

                if (request.requestee.email == requestee.email || request.team.coaches.Contains(requestee, new PersonComparer())) {
                    // Remove the request to the database
                    result = "Error making the request.";
                    if (dba.RemoveRequest(requestID)) {
                        result = "Request removed.";
                    }
                } else {
                    result = "Invalid attempt to remove request.";
                    String message = "Attempt to remove 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.REMOVE_REQUEST_JOIN, LogAction.NA);
                    entry.User = requestee;
                    entry.Message = message;
                    dba.LogMessage(entry);
                }
            }

            // Return the success message of the removal
            return Json(
                new { message = result },
                JsonRequestBehavior.AllowGet
            );
        }
예제 #5
0
        public ActionResult DeclineCoachRequest(long requestID)
        {
            String result = "Request deleted.";
            DBAccessor dba = new DBAccessor();

            // Get the request from the DB
            Request request = dba.GetRequest(requestID, RequestType.COACH_PERMISSION);

            if (!dba.RemoveRequest(requestID)) {
                result = "Error deleting request.";
            }
            else {
                // Form an email
                MailMessage newMessage = new MailMessage();
                SmtpClient mailService = new SmtpClient();

                //set the addresses
                newMessage.From = new MailAddress(AppConstants.EMAIL_ADMIN);
                newMessage.To.Add(request.requestee.email);

                //set the content
                newMessage.Subject = "Coach Permission Declined";
                newMessage.Body = "Your request to receive coach permission at dugoutdigits.com has been declined.";

                //send the message
                mailService.UseDefaultCredentials = false;
                mailService.DeliveryMethod = SmtpDeliveryMethod.Network;
                mailService.Host = AppConstants.EMAIL_SMTP_ADDRESS;
                mailService.Credentials = new NetworkCredential(AppConstants.EMAIL_SMTP_USERNAME, AppConstants.EMAIL_SMTP_PASSWORD);
                mailService.Send(newMessage);
            }

            return Json(
                new { message = result },
                JsonRequestBehavior.AllowGet
            );
        }