// GET api/<controller> public IEnumerable<Player> Get() { using (var db = new TennisDb()) { return db.Players.ToArray(); } }
// GET api/matches public IEnumerable<MatchRaw> Get() { using (var db = new TennisDb()) { return db.Matches.ToArray(); } }
public MatchController() { using (var db = new TennisDb()) { PlayerList = db.Players.ToArray(); } //using (var dr = TennisObjects.DataAccess.GetAllPlayers()) // PlayerList = TennisObjects.Player.GetList(dr); }
// GET api/<controller>/5 public Player Get(int id) { using (var db = new TennisDb()) { var query = from p in db.Players where p.Id == id select p; if (!query.Any()) { //need to throw a 404 exception //return HttpStatusCode.NotFound; } return query.First(); } }
// GET api/matches/5 public MatchRaw Get(int id) { using (var db = new TennisDb()) { var query = from item in db.Matches where item.ID == id select item; if (!query.Any()) { //need to throw a 404 exception //return HttpStatusCode.NotFound; } return query.First(); } }
public static void PrintMatches() { TennisDb db = new TennisDb(); TennisDb dbPlayer = new TennisDb(); Console.WriteLine(); foreach (var matchRaw in db.Matches) { var match = matchRaw.ToMatch(); var playerMatch = match.ToPlayerMatch(1); var opponent = dbPlayer.Players.Find(playerMatch.OpponentID); //Console.Write(match.ToString().PadRight(80)); //Console.WriteLine(playerMatch.ToString()); //Console.WriteLine("{0} Player {1} d. Player {2} {3}-{4} {5}-{6} {7}-{8}{9}", match.Date, playerMatch.OpponentName, match.Score, match.Defaulted ? " default" : ""); Console.WriteLine("{0},{1},{2},{3}", match.Date, opponent.FullName, playerMatch.Result, playerMatch.Score); } }