/// <summary> /// Returns a list of the players tied to the team with the given team ID in the form /// of an unordered list. /// </summary> /// <param name="teamID">The ID of the team in interest.</param> /// <returns>An unordered list of the players on the team.</returns> public ActionResult AJAX_GetTeamMembers(long teamID) { string result = "Request is not authenticated."; if (Request.IsAuthenticated) { DBAccessor dba = new DBAccessor(); Team team = dba.GetTeamDetails(teamID); Person user = new Person(); user.email = User.Identity.Name; if (team.coaches.Contains(user, new PersonComparer()) || team.players.Contains(user, new PersonComparer())) { result = "<ul>"; foreach (Person player in team.players) { result += "<li>" + player.firstName + " " + player.lastName + "</li>"; } result += "</ul>"; } else { result = "You must be on the team or a coach of the team to view the players."; LogEntry entry = new LogEntry(LogType.INVALID_REQUEST, LogFunction.GET_TEAM_MEMBERS, LogAction.NA); entry.User = user; entry.Message = "Attempt to view players of " + team.name + " (" + team.ID + ")."; dba.LogMessage(entry); } } // Return the success message of the removal return Json( new { message = result }, JsonRequestBehavior.AllowGet ); }
/// <summary> /// Sends an invite email to the given email with the given message. /// </summary> /// <param name="inviteEmail">The email of the person to invite.</param> /// <param name="inviteMessage">The message to send with the invitation.</param> /// <returns>Success of the call.</returns> public ActionResult AJAX_InviteUser(string inviteEmail, string inviteMessage, long teamID) { string successMessage = "Message sent to " + inviteEmail; // Make sure the request is authenticated if (Request.IsAuthenticated) { // Make sure the invite email is bound if (inviteEmail != null && !inviteEmail.Equals("")) { // Validate the request DBAccessor dba = new DBAccessor(); Person user = dba.GetPersonInformation(User.Identity.Name); string name = user.firstName + " " + user.lastName; Team team = dba.GetTeamDetails(teamID); if (team.coaches.Contains(user, new PersonComparer())) { try { // Add the invite to the database long inviteID = dba.AddInvite(inviteEmail, user.ID, teamID); // Form an email String body = ""; if (inviteMessage != null && !inviteMessage.Equals("")) { body += "See " + name + "'s message below:\n\n" + inviteMessage + "\n\n"; } body += "To join the " + team.name + " visit http://dugoutdigits.com/Team/Join?id=" + inviteID + "&email=" + inviteEmail + " and follow the instructions."; MailMessage newMessage = new MailMessage(); SmtpClient mailService = new SmtpClient(); //set the addresses newMessage.From = new MailAddress(AppConstants.EMAIL_ADMIN); newMessage.To.Add(inviteEmail); //set the content newMessage.Subject = name + " has invited you to join the " + team.name; newMessage.Body = body; //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); } catch (Exception) { successMessage = "Error sending email to " + inviteEmail; } } else { successMessage = "Invalid attempt to invite user."; LogEntry entry = new LogEntry(LogType.INVALID_REQUEST, LogFunction.INVITE_USER, LogAction.NA); entry.User = user; entry.Message = "Attempt to invite "+inviteEmail+" to join "+team.name+" (ID "+team.ID+")."; dba.LogMessage(entry); } } else { successMessage = "Please enter the email of the person you are trying to invite."; } } else { successMessage = "The request was not authenticated."; } // Return the success message of the addition return Json( new { message = successMessage }, JsonRequestBehavior.AllowGet ); }
/// <summary> /// Get's the seasons tied to the team with the given ID in the form of an /// unordered list. /// </summary> /// <param name="teamID">The ID of the team in interest.</param> /// <returns>An unordered list of the seasons.</returns> public ActionResult AJAX_GetSeasons(long teamID) { string result = "Request is not authenticated."; if (Request.IsAuthenticated) { DBAccessor dba = new DBAccessor(); Team team = dba.GetTeamDetails(teamID); Person user = new Person(); user.email = User.Identity.Name; if (team.coaches.Contains(user, new PersonComparer()) || team.players.Contains(user, new PersonComparer())) { List<Season> seasons = dba.GetSeasons(teamID); if (seasons.Any()) { result = "<ul>"; foreach (Season season in seasons) { result += "<li>" + season.year + "</li>"; } result += "</ul>"; } else { result = "<p>There are currently no seasons for this team.</p>"; } } else { result = "You must be on the team or a coach of the team to view the seasons."; LogEntry entry = new LogEntry(LogType.INVALID_REQUEST, LogFunction.GET_SEASONS, LogAction.NA); entry.User = user; entry.Message = "Attempt to view seasons of " + team.name + " ("+team.ID+")."; dba.LogMessage(entry); } } // Return the success message of the removal return Json( new { message = result }, JsonRequestBehavior.AllowGet ); }
/// <summary> /// Adds the given season to the team with the matching team ID. /// </summary> /// <param name="teamID">The ID of the team of interest.</param> /// <param name="season">The season to be added to the team of interest.</param> /// <returns>A message detailing the result of the addition.</returns> public ActionResult AJAX_AddSeason(long teamID, short season) { string result = "Request is not authenticated."; if (Request.IsAuthenticated) { DBAccessor dba = new DBAccessor(); Team team = dba.GetTeamDetails(teamID); Person user = new Person(); user.email = User.Identity.Name; if (team.coaches.Contains(user, new PersonComparer())) { result = "Error adding season " + season + " to " + team.name + "."; if (dba.AddSeason(teamID, season)) { result = "Season " + season + " added to " + team.name + "."; } } else { result = "You must be a coach of the team to add a season."; LogEntry entry = new LogEntry(LogType.INVALID_REQUEST, LogFunction.ADD_SEASON, LogAction.NA); entry.User = user; entry.Message = "Attempt to add a season to "+team.name + " (" + team.ID + ")."; dba.LogMessage(entry); } } return Json( new { message = result }, JsonRequestBehavior.AllowGet ); }
/// <summary> /// Creates a practice object with the given information, ties it to the team with /// the given team ID and saved the game to the database. /// </summary> /// <param name="teamID">The ID of the team of interest.</param> /// <param name="location">The location of the practice.</param> /// <param name="date">The date of the practice (M/D).</param> /// <param name="time">The time of the practice (H/MM TT).</param> /// <param name="seasonID">The ID of the season is is being added to.</param> /// <returns>A message detailing the result of the addition.</returns> public ActionResult AJAX_AddPractice(long teamID, string location, string date, string time, long seasonID) { string result = "Request is not authenticated."; if (Request.IsAuthenticated) { DBAccessor dba = new DBAccessor(); Team team = dba.GetTeamDetails(teamID); Person user = new Person(); user.email = User.Identity.Name; Season season = dba.GetSeason(seasonID); if (team.coaches.Contains(user, new PersonComparer())) { try { DateTime practiceDate = Parser.ParseDateAndTime(date, time, season.year); Practice practice = new Practice(); practice.location = location; practice.season = season; practice.date = practiceDate; if (dba.AddPractice(practice)) { result = "Practice sucessfully added to the season."; } else { result = "Error adding the practice to the season."; } } catch { result = "An invalid date was given."; } } else { result = "You must be a coach of the team to add a practice."; LogEntry entry = new LogEntry(LogType.INVALID_REQUEST, LogFunction.ADD_PRACTICE, LogAction.NA); entry.User = user; entry.Message = "Attempt to add a practice to " + team.name + " (" + team.ID + ")."; dba.LogMessage(entry); } } return Json( new { message = result }, JsonRequestBehavior.AllowGet ); }
public ActionResult Stats() { // If the request isn't logged in redirect to Logon. if (Request.IsAuthenticated) { // Try to get the team ID from the URL long teamID = 0; try { teamID = Convert.ToInt64(Request.QueryString["teamID"]); } catch { return RedirectToAction("Index", "Home"); } // Get the team information DBAccessor dba = new DBAccessor(); Team team = dba.GetTeamDetails(teamID); Person user = new Person(); user.email = User.Identity.Name; ViewBag.Title = team.name; ViewBag.Name = team.name; ViewBag.LogoURL = team.logoURL; ViewBag.TeamID = team.ID; ViewBag.IsCoach = team.coaches.Contains(user, new PersonComparer()); return View(); } return RedirectToAction("LogOn", "Account"); }
/// <summary> /// Removes a team from the database with the matching teamID. /// </summary> /// <param name="teamID">The ID of the team to remove from the database.</param> /// <returns>A message telling if the removal was successful.</returns> public ActionResult AJAX_RemoveTeam(long teamID) { string result = "Request not authenticated."; if (Request.IsAuthenticated) { // Get the team that is to be removed to validate the authenticated user can remove it DBAccessor dba = new DBAccessor(); Team team = dba.GetTeamDetails(teamID); Person user = new Person(); user.email = User.Identity.Name; if (team.coaches.Contains(user, new PersonComparer())) { if (dba.RemoveTeam(teamID)) { result = "Team removed successfully."; } else { result = "Error removing the team from the database."; } } else { result = "Invalid attempt to remove team."; LogEntry entry = new LogEntry(LogType.INVALID_REQUEST, LogFunction.REMOVE_TEAM, LogAction.NA); entry.User = user; entry.Message = "Attempt to remove the team " + team.name + "(ID: " + team.ID + ")."; dba.LogMessage(entry); } } // Return the success message of the addition return Json( new { message = result }, JsonRequestBehavior.AllowGet ); }