public GamblerService(BetsKingDbContext dbContext, IHttpContextAccessor httpContextAccessor, IOptions <AuthSettings> authSettings) { _dbContext = dbContext; _passwordHasher = new PasswordHasher <Gambler>(); _httpContextAccessor = httpContextAccessor; _authSettings = authSettings.Value; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, BetsKingDbContext dbContext) { app.UseAuthentication(); app.UseResponseCompression(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(routes => { routes.MapRoute(name: "default", template: "{controller}/{action}/{id?}"); }); app.UseBlazor <Client.Program>(); if (env.IsDevelopment()) { InitDev(dbContext); } else { InitProd(dbContext); } }
private void InitData(BetsKingDbContext dbContext) { if (!dbContext.Roles.Any()) { dbContext.Roles.Add(new Role { Name = "Gambler" }); dbContext.Roles.Add(new Role { Name = "Admin" }); dbContext.SaveChanges(); } if (dbContext.Gamblers.FirstOrDefault(g => g.UserName.Equals(Configuration["DbInit:AdminUserName"], StringComparison.InvariantCultureIgnoreCase)) == null) { var admin = new Gambler { UserName = Configuration["DbInit:AdminUserName"], DisplayName = Configuration["DbInit:AdminDisplayName"] }; var passwordHasher = new PasswordHasher <Gambler>(); admin.Password = passwordHasher.HashPassword(admin, Configuration["DbInit:AdminPassword"]); var entry = dbContext.Gamblers.Add(admin); dbContext.SaveChanges(); dbContext.UserRoles.AddRange(new UserRole { GamblerId = entry.Entity.Id, RoleId = 1 }, new UserRole { GamblerId = entry.Entity.Id, RoleId = 2 }); dbContext.SaveChanges(); } }
public MatchBetService(BetsKingDbContext dbContext) { _dbContext = dbContext; }
public RoundService(BetsKingDbContext dbContext) { _dbContext = dbContext; }
public MatchService(BetsKingDbContext dbContext, IMatchBetService matchBetService) { _dbContext = dbContext; _matchBetService = matchBetService; }
public void InitProd(BetsKingDbContext dbContext) { dbContext.Database.Migrate(); InitData(dbContext); }
public void InitDev(BetsKingDbContext dbContext) { dbContext.Database.EnsureCreated(); InitData(dbContext); }