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 ); }
/// <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 ); }
/// <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 ); }
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 ); }