// GET api/<controller> public IEnumerable<Team> GetAllPools() { try { List<Team> teams = new List<Team>(); string connectionString = ConfigurationManager.ConnectionStrings["FreeFootieConnectionString"].ConnectionString; using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString)) { var results = (from c in myData.teams orderby c.id ascending select c).ToList(); foreach (var temp in results) { Team team = new Team(); team.id = temp.id; team.name = temp.name; team.coach = temp.coach; team.loses = temp.losses; team.wins = temp.wins; team.ties = temp.ties; team.phone = temp.phone; team.school = temp.schoolID; var playerIDs = (from c in myData.teamPlayers where c.teamID == temp.id select c.playerID).ToList().ToArray(); team.palyers = playerIDs; teams.Add(team); } } return teams; } catch (Exception ex) { Common.ErrorCatch(ex, "TeamController.GetAllPools"); return null; } }
// GET api/<controller>/5 public Team GetTeamById(int id) { try { string connectionString = Properties.Settings.Default.FreeFootieConnectionString; using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString)) { var temp = (from c in myData.teams where c.id == id orderby c.id ascending select c).SingleOrDefault(); Team team = new Team(); team.id = temp.id; team.name = temp.name; team.coach = temp.coach; team.loses = temp.losses; team.wins = temp.wins; team.ties = temp.ties; team.phone = temp.phone; team.school = temp.schoolID; var playerIDs = (from c in myData.teamPlayers where c.teamID == temp.id select c.playerID).ToList().ToArray(); team.palyers = playerIDs; return team; } } catch (Exception ex) { Common.ErrorCatch(ex, "TeamController.GetTeamById"); return null; } }
// POST api/<controller> public void PostTeam(Team team) { try { string connectionString = Properties.Settings.Default.FreeFootieConnectionString; using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString)) { using (TransactionScope myScope = new TransactionScope()) { team newTeam = new team(); var newID = (from c in myData.teams select c.id).Max(); newTeam.id = newID + 1; newTeam.name = team.name; newTeam.coach = team.coach; newTeam.losses = team.loses; newTeam.wins = team.wins; newTeam.ties = team.ties; newTeam.phone = team.phone; newTeam.schoolID = team.school; myData.teams.InsertOnSubmit(newTeam); foreach (int playerID in team.palyers) { teamPlayer newTeamPlayer = new teamPlayer(); newTeamPlayer.teamID = newTeam.id; newTeamPlayer.playerID = playerID; myData.teamPlayers.InsertOnSubmit(newTeamPlayer); } myData.SubmitChanges(); myScope.Complete(); } } } catch (Exception ex) { Common.ErrorCatch(ex, "TeamController.PostTeam"); } }