Guid AddJob() { var jobId = Guid.NewGuid(); Context.RankingJobs.Add(new Data.RankingJob() { Id = jobId, State = Data.RankingJobStates.Running, StartedOn = DateTime.Now }); Context.SaveChanges(); return(jobId); }
public void Initialise() { var options = new DbContextOptionsBuilder <Data.PingPongContext>().UseInMemoryDatabase(databaseName: "PingPong" + Guid.NewGuid().ToString()).Options; Context = new Data.PingPongContext(options); Player1 = new Data.Player() { Id = Guid.NewGuid(), FirstName = "Test1Firstname", LastName = "Test1Lastname" }; Player2 = new Data.Player() { Id = Guid.NewGuid(), FirstName = "Test2Firstname", LastName = "Test2Lastname" }; Player3 = new Data.Player() { Id = Guid.NewGuid(), FirstName = "Test3Firstname", LastName = "Test3Lastname" }; Player4 = new Data.Player() { Id = Guid.NewGuid(), FirstName = "Test4Firstname", LastName = "Test4Lastname" }; Player5 = new Data.Player() { Id = Guid.NewGuid(), FirstName = "Test5Firstname", LastName = "Test5Lastname" }; Player6 = new Data.Player() { Id = Guid.NewGuid(), FirstName = "Test6Firstname", LastName = "Test6Lastname" }; Context.Players.Add(Player1); Context.Players.Add(Player2); Context.Players.Add(Player3); Context.Players.Add(Player4); Context.Players.Add(Player5); Context.Players.Add(Player6); //populate the games AddGame(Context, Player1.Id, Player2.Id, 5, 3, Player1.Id); AddGame(Context, Player1.Id, Player3.Id, 7, 4, Player1.Id); AddGame(Context, Player1.Id, Player4.Id, 6, 3, Player1.Id); AddGame(Context, Player2.Id, Player3.Id, 5, 3, Player2.Id); AddGame(Context, Player2.Id, Player4.Id, 5, 3, Player2.Id); AddGame(Context, Player3.Id, Player4.Id, 5, 3, Player3.Id); Context.SaveChanges(); this.Context = new Data.PingPongContext(options); this.Service = new PlayerRanker(Context); }
public void Post(Player player) { try { Console.WriteLine("test3"); var context = new PingPongContext(); Console.WriteLine("test1"); // save new player context.Add(player); Console.WriteLine("test2"); context.SaveChanges(); } catch (Exception e) { Console.WriteLine(e.ToString()); } }
public void Put(Player player) { var context = new PingPongContext(); var players = context.Players.ToList(); var entity = players.Find(i => i.Id == player.Id); Console.WriteLine(player.Id); // if player to update is not found return if (entity == null) { Console.WriteLine("TEST2"); return; } Console.WriteLine("TEST3"); // save updated player context.Entry(entity).CurrentValues.SetValues(player); context.SaveChanges(); }
public void Delete(int id) { var context = new PingPongContext(); var player = new Player() { Id = id }; context.Players.Attach(player); context.Players.Remove(player); context.SaveChanges(); /*var context = new PingPongContext(); * var player = context.Players.ToList(); * player.Find(i => i.Id == id); * * if (player != null) * { * context.Remove(player); * context.SaveChanges(); * }*/ }
public static void InitializeMockDatabaseRecords(PingPongContext context, int count = 5) { context.Players.AddRange(GetSeedData(count)); context.SaveChanges(); }