public async Task<IHttpActionResult> GetTeamRank(int id) { Trace.TraceInformation("Getting rank for team {0}", id); var dataContext = new AppServiceDataContext(); var repository = new Repository(dataContext); var team = await repository.GetByIdAsync<Team>(id); if (team == null) { Trace.TraceWarning("Team not found in database: {0}", id); return NotFound(); } return Ok(team); }
public static async Task UpdateRank() { using (var dataContext = new AppServiceDataContext()) { var repository = new Repository(dataContext); var team = await repository.Query<Team>().FirstOrDefaultAsync(); if (team != null) { Console.WriteLine("Loaded team: {0}", team.Id); var random = new Random(); var increment = random.Next(-5, 5); team.Rank += increment; await repository.SaveChangesAsync(); Console.WriteLine("Updated team rank to: {0}", team.Rank); } } }
public TeamsController() { var dataContext = new AppServiceDataContext(); this.repository = new Repository(dataContext); }