/// <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> /// Removes the invite matching the given invite ID from the database. /// </summary> /// <param name="inviteID">The ID of the invite to remove.</param> /// <returns>Success message of the invite removal.</returns> public ActionResult AJAX_RemoveInvite(long inviteID) { // Make sure the user is authenticated string result = "Request not authenticated."; if (Request.IsAuthenticated) { DBAccessor dba = new DBAccessor(); Invitation invite = dba.GetInvite(inviteID); if (invite.invitor.email.Equals(User.Identity.Name) || invite.invitee == User.Identity.Name) { // Remove the request to the database result = "Error making the request."; if (dba.RemoveInvite(inviteID)) { result = "Invitation removed."; } } else { result = "Invalid request to remove invite."; LogEntry entry = new LogEntry(LogType.INVALID_REQUEST, LogFunction.REMOVE_INVITE, LogAction.NA); entry.User = new Person("NA", "NA", User.Identity.Name, "NA"); entry.Message = "Attempt to remove invite (ID " + invite.ID + ")."; dba.LogMessage(entry); } } // Return the success message of the removal return Json( new { message = result }, JsonRequestBehavior.AllowGet ); }
/// <summary> /// Returns the details for a single invite denoted by the given invite ID. /// </summary> /// <param name="inviteID">The ID of the invite in interest.</param> /// <returns>Returns an HTML format with the details of the invite.</returns> public ActionResult AJAX_GetInvite(long inviteID) { string result = "<p>Could not authenticate the request.</p>\n"; if (Request.IsAuthenticated) { DBAccessor dba = new DBAccessor(); Invitation invite = dba.GetInvite(inviteID); if (invite != null) { // Form the player information result = "<div class='lightbox-content-close clickable-text' onclick='action_hidedetails()'>Close</div>"; result += "<h3>Pending Invite</h3>\n"; result += "<div id='invite-details-left'>\n<img src='" + invite.invitor.imageURL + "' alt='coach picture' />\n</div>\n"; result += "<div id='invite-details-right'>\n"; result += "<p>Invited by " + invite.invitor.firstName + " " + invite.invitor.lastName + "</p>\n"; result += "<p>Invitation to join the " + invite.team.name + "</p>\n"; result += "<img src='./../Content/images/accept.png' height='20' width='20' class='request-action-image' alt='accept' onClick='action_acceptinvite(" + invite.ID + ")' />"; result += "<img src='./../Content/images/decline.png' height='20' width='20' class='request-action-image' margin-right='5px' alt='decline' onClick='action_declineinvite(" + invite.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 invite.</p>"; result += "</div>\n"; } } return Json( new { message = result }, JsonRequestBehavior.AllowGet ); }