// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, WorldCupContext context) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); DbInitializer.Initialize(context); }
public async Task <Bet> CreateBet(WorldCupContext context) { var match = await context.Matches.FirstOrDefaultAsync(c => c.Id == MatchId); if (match == null) { throw new Exception("No match found for MatchId"); } return(new Bet { UserId = UserId, AwayGoals = AwayGoals, AwayGoalsInExtraTime = AwayGoalsInExtraTime, AwayGoalsInFirstHalf = AwayGoalsInFirstHalf, AwayPenatly = AwayPenatly, BetId = Guid.NewGuid(), HasExtraTime = HasExtraTime, HasPenatly = HasPenatly, HomeGoals = HomeGoals, HomeGoalsInExtraTime = HomeGoalsInExtraTime, HomeGoalsInFirstHalf = HomeGoalsInFirstHalf, HomePenatly = HomePenatly, Id = Guid.NewGuid(), TimeStamp = DateTime.Now, Match = match }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, WorldCupContext worldCupContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } // Seed DB worldCupContext.DataSeed(); // Configure API app.UseHttpsRedirection(); app.UseExceptionHandlerWithProblemJson(); app.UseMvc(); app.UseOpenApi(); // Configure Automapper app.UseAutoMapper(mapperConfig => { mapperConfig.CreateMap <Entities.Team, Models.TeamDto>(); mapperConfig.CreateMap <Entities.Team, Models.TeamDetailsDto>(); mapperConfig.CreateMap <Entities.Player, Models.PlayerDto>(); mapperConfig.CreateMap <Models.PlayerDto, Entities.Player>(); }); }
public static void DataSeed(this WorldCupContext context) { if (context.Teams.Any()) { return; } var teams = new List <Team> { new Team { Name = "Belgium", Description = "The one with that big park.", UpdatedOn = DateTime.Now.AddDays(value: -1), Continent = ContinentCode.Europe, Players = new List <Player> { new Player { FirstName = "Hazard", Description = "He plays in Chelsea.", IsTopPlayer = true }, new Player { FirstName = "De Bruyne", Description = "He scored the last match." } } }, new Team { Name = "France", Description = "One time world cup winner.", Continent = ContinentCode.Europe, UpdatedOn = DateTime.Now, Players = new List <Player> { new Player { FirstName = "MBappe", Description = "19 years old striker." }, new Player { FirstName = "Pogba", Description = "He plays for MUTD.", IsTopPlayer = true } } } }; context.Teams.AddRange(teams); context.SaveChanges(); }
private ITeamRepository GetInMemoryTeamRepository() { DbContextOptions<WorldCupContext> options; var builder = new DbContextOptionsBuilder<WorldCupContext>(); options = builder.UseInMemoryDatabase(databaseName: "WorldCupDB").Options; var worldCupContext = new WorldCupContext(options); worldCupContext.Database.EnsureDeleted(); worldCupContext.Database.EnsureCreated(); return new TeamRepository(worldCupContext); }
public static async Task <IList <MatchByUser> > GetByUserId(WorldCupContext context, Guid userId) { List <MatchByUser> result = new List <MatchByUser>(); var matches = await context.Matches.Include(match => match.Bets).Include(match => match.Result).Include(match => match.HomeTeam) .Include(match => match.AwayTeam).ToListAsync(); foreach (var match in matches) { var bet = match.Bets.FirstOrDefault(c => c.UserId == userId); result.Add(new MatchByUser { Bet = bet, Match = match }); } return(result); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, WorldCupContext worldCupContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } // Seed DB worldCupContext.DataSeed(); // Configure API app.UseHttpsRedirection(); app.UseExceptionHandlerWithProblemJson(); app.UseStatusCodePagesWithReExecute("/errors/{0}"); app.UseMvc(); app.UseOpenApi(); // Configure Automapper AutoMapperConfig.Initialize(); }
public void TestWorldCupContext() { /* ================== Montando Cenario =================== */ var options = new DbContextOptionsBuilder <WorldCupContext>() .UseInMemoryDatabase(databaseName: "WorldCupDB").Options; /* ================== Execucao =================== */ using (var ctx = new WorldCupContext(options)) { ctx.Teams.Add(new Team { Name = "Brasil", Flag = "BRA" }); ctx.SaveChanges(); /* ================== Verificacao =================== */ // Testando com Assert Assert.NotEmpty(ctx.Teams.ToList()); // Testando com FluentAssertions //ctx.Teams.ToList().Should().NotBeEmpty(ctx.Teams.ToList().ToString(), // $"O objeto esperado não corresponde com ao objeto obtido ({ctx.Teams.ToList().ToString()})"); } }
public BaseRepository(WorldCupContext context) { _ctx = context; }
public CountriesController(WorldCupContext context) { _context = context; }
public AddResultModel(WorldCupContext context) { _context = context; }
public PlayersController(WorldCupContext context) { _context = context; }
public ListModel(WorldCupContext dbContext) { _dbContext = dbContext; }
public TeamRepository(WorldCupContext context) : base(context) { }
public DashboardModel(WorldCupContext context) { _context = context; }
public WorldCupRepository(WorldCupContext context) { _context = context; //_context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; }
public AddModel(WorldCupContext context) { _context = context; }