/// <summary> /// Returns a list of teams associated with the authenticated user. /// </summary> /// <returns>HTML table containing a list of teams.</returns> public ActionResult AJAX_GetTeamsTable() { string result = "<p>Could not authenticate the request.</p>\n"; if (Request.IsAuthenticated) { result = ""; // Get the teams associated with the user who's logged in DBAccessor dba = new DBAccessor(); List<Team> teamsCoached = dba.GetTeamListCoach(User.Identity.Name); List<Team> teamsMember = dba.GetTeamListMember(User.Identity.Name); // Create table to hold the team names if (teamsCoached.Any() || teamsMember.Any()) { result += "<table>\n"; result += "<tr><th>Team Name</th><th>Coached By</th><th>Action</th></tr>\n"; foreach (Team team in teamsCoached) { result += "<tr><td><div class='clickable-text'>" + team.name + "</div></td><td>You</td><td><div onClick='action_detailsremoveteam(" + team.ID + ")' class='clickable-text'>Remove</div></td></tr>\n"; } foreach (Team team in teamsMember) { string coachNames = team.coaches[0].firstName + " " + team.coaches[0].lastName; for (int i = 1; i < team.coaches.Count; i++) { coachNames += ", " + team.coaches[i].firstName + " " + team.coaches[i].lastName; } result += "<tr><td><div class='clickable-text'>" + team.name + "</div></td><td>" + coachNames + "</td><td><div onClick='action_leaveteam(" + team.ID + ")' class='clickable-text'>Leave</div></td></tr>\n"; } result += "</table>\n"; } else { result += "<p>You haven't added or joined any teams. Add or search for a team using the controls above.</p>"; } } return Json( new { message = result }, JsonRequestBehavior.AllowGet ); }
public ActionResult AJAX_GetTeams2(long teamID) { // Get the teams associated with the user who's logged in DBAccessor dba = new DBAccessor(); List<Team> teams = dba.GetTeamListCoach(User.Identity.Name); teams.AddRange(dba.GetTeamListMember(User.Identity.Name)); // See if a team to match was given, if so, move it to the front int i = teams.FindIndex(t => t.ID.Equals(teamID)); Team temp = teams[i]; teams[i] = teams[0]; teams[0] = temp; // Create ul to hold the team names string result = "<ul>\n"; foreach (Team team in teams) { result += "<li><div onClick='action_gototeam(" + team.ID + ")'>" + team.name + "</div></li>\n"; } result += "</ul>\n"; return Json( new { message = result }, JsonRequestBehavior.AllowGet ); }
/// <summary> /// Returns an HTML drop down containing a list of teams the logged in /// user is associated with. The association parameter allows you to /// pick if you want teams the user coaches (0), is a member of (1) or /// both (2). /// </summary> /// <param name="association">The desired associativity of the user to the teams.</param> /// <returns>An HTML drop down the teams the user is associated with.</returns> public ActionResult AJAX_GetTeamsDropDown(int association) { // Get the teams associated with the user who's logged in DBAccessor dba = new DBAccessor(); List<Team> teamsCoach = new List<Team>(); List<Team> teamsMember = new List<Team>(); if (association == 0 || association == 2) { teamsCoach = dba.GetTeamListCoach(User.Identity.Name); } if (association == 1 || association == 2) { teamsMember = dba.GetTeamListMember(User.Identity.Name); } // Create dropdown to hold the teams string result = "<select class='editor-field' id='teamdropdown'>\n"; foreach (Team team in teamsCoach) { result += "<option value='" + team.ID + "'>" + team.name + "</option>\n"; } foreach (Team team in teamsMember) { result += "<option value='" + team.ID + "'>" + team.name + "</option>\n"; } result += "</select>\n"; return Json( new { message = result }, JsonRequestBehavior.AllowGet ); }
/// <summary> /// Gets the list of teams (in the form of an ul) associated with the /// user who is currently logged in. /// </summary> /// <returns>List of teams (name only).</returns> public ActionResult AJAX_GetTeams() { // Get the teams associated with the user who's logged in DBAccessor dba = new DBAccessor(); List<Team> teams = dba.GetTeamListCoach(User.Identity.Name); teams.AddRange(dba.GetTeamListMember(User.Identity.Name)); // Create ul to hold the team names string result = "<ul>\n"; foreach (Team team in teams) { result += "<li><div onClick='action_gototeam(" + team.ID + ")'>" + team.name + "</div></li>\n"; } result += "</ul>\n"; return Json( new { message = result }, JsonRequestBehavior.AllowGet ); }