public async Task <ActionResult> Create() { using (var db = new GameStatisticsContext()) { var statistics = await db.Statistics.ToListAsync(); return(Ok(statistics)); } }
public async Task <ActionResult> Create(string gameId) { using (var db = new GameStatisticsContext()) { var statistics = await db.Statistics.Where(s => s.GameId.Equals(gameId)).ToListAsync(); return(Ok(statistics)); } }
private static void Project(GameStarted @event) { var gameId = @event.Id.Value; using (var db = new GameStatisticsContext()) { foreach (var player in @event.Players) { db.Add(new GameStatistic { GameId = gameId, PlayerId = player.Value }); } db.SaveChanges(); } }
private static void Project(DiceRolled @event) { var gameId = @event.Id.Value; var player = @event.Player.Value; using (var db = new GameStatisticsContext()) { var statistic = db.Statistics.FirstOrDefault(s => s.GameId.Equals(gameId) && s.PlayerId.Equals(player)); if (statistic != null) { statistic.NumberRolled = @event.RolledNumber; db.SaveChanges(); } else { Context.GetLogger().Warning("Unable to find GameStatistic readmodel for game id {0} and player id {1}", gameId, player); } } }
private static void Project(GameFinished @event) { var gameId = @event.Id.Value; using (var db = new GameStatisticsContext()) { foreach (var player in @event.Winners) { var statistic = db.Statistics.FirstOrDefault(s => s.GameId.Equals(gameId) && s.PlayerId.Equals(player.Value)); if (statistic != null) { statistic.Winner = true; } else { Context.GetLogger().Warning("Unable to find GameStatistic readmodel for game id {0} and player id {1}", gameId, player); } } db.SaveChanges(); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime lifetime) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); c.RoutePrefix = string.Empty; }); //Create readmodel database using (var db = new GameStatisticsContext()) { db.Database.EnsureCreated(); } //ActorSystem lifetime management lifetime.ApplicationStarted.Register(() => { app.ApplicationServices.GetService <ActorSystem>(); // start Akka.NET }); lifetime.ApplicationStopping.Register(() => { app.ApplicationServices.GetService <ActorSystem>()?.Terminate().Wait(); }); }