public IEnumerable <Player> Get() { var context = new PingPongContext(); var players = context.Players.ToList(); return(players); }
public Player Get(int Id) { var context = new PingPongContext(); var players = context.Players.ToList(); var player = players.Where(i => i.Id == Id).FirstOrDefault <Player>(); return(player); }
public MockControllerFixture() { DbContextOptions <PingPongContext> options = new DbContextOptionsBuilder <PingPongContext>() .UseInMemoryDatabase(databaseName: "PingPongTesting") .Options; DbContext = new PingPongContext(options); DatabaseSeed.InitializeMockDatabaseRecords(DbContext); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, PingPongContext dbContext) { dbContext.Database.EnsureCreated(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); app.UseHsts(); app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto }); } app.UseHttpsRedirection(); app.UseStaticFiles(); if (!env.IsDevelopment()) { app.UseSpaStaticFiles(); } // Enable the Swagger UI middleware and the Swagger generator app.UseOpenApi(); app.UseSwaggerUi3(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller}/{action=Index}/{id?}"); }); app.UseSpa(spa => { // To learn more about options for serving an Angular SPA from ASP.NET Core, // see https://go.microsoft.com/fwlink/?linkid=864501 spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseAngularCliServer(npmScript: "start"); // spa.UseProxyToSpaDevelopmentServer("http://localhost:4200"); } }); }
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 DatabaseFixture() { DbContextOptions <PingPongContext> options = new DbContextOptionsBuilder <PingPongContext>() .UseInMemoryDatabase(databaseName: "PingPongTesting") .Options; DbContext = new PingPongContext(options); TestPlayer = new Player { FirstName = "John", LastName = "Doe", Email = "*****@*****.**", Age = 99, SkillLevel = SkillLevel.Beginner }; }
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 StatisticsController(PingPongContext context) { _context = context; }
public DetailsController(PingPongContext context) { detailsPlayerContext = context; }
public static void InitializeMockDatabaseRecords(PingPongContext context, int count = 5) { context.Players.AddRange(GetSeedData(count)); context.SaveChanges(); }
public PlayerController(PingPongContext context) { this.context = context; }
public HomeController(PingPongContext context) { homePlayerContext = context; }