// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } // custom jwt auth middleware app.UseMiddleware<JwtMid>(); app.UseHttpsRedirection(); app.UseMvc(); using (var db = new ScoreDbContext()) { db.Database.EnsureCreated(); db.Database.Migrate(); } // global cors policy app.UseCors(x => x .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); //app.UseEndpoints(endpoints => endpoints.MapControllers()); }
/// <summary> /// Filters the leaderboard objects by a specific search condition. /// </summary> /// <param name="searchCondition">Condition which the leaderboard entries searched by.</param> /// <returns>The filtered leaderboard.</returns> protected override async Task <IEnumerable <LeaderboardEntry> > GetEntries(Expression <Func <LeaderboardEntry, bool> > searchCondition) { using (var context = new ScoreDbContext()) { var query = context.Leaderboards.Where(searchCondition).OrderByDescending(l => l.Score).Select(l => l); return(await query.ToArrayAsync()); } }
/// <summary> /// Adds a new entry to the leaderboards. /// </summary> /// <param name="entry">New entry to be added.</param> /// <returns>Void result of task execution.</returns> public override async Task AddLeaderboardEntryAsync(LeaderboardEntry entry) { using (var context = new ScoreDbContext()) { context.Leaderboards.Add(entry); await context.SaveChangesAsync(); } }
/// <summary> /// /// </summary> /// <param name="configuration"></param> public StudentScoreController(IConfiguration configuration, ICommonService commonService, ScoreDbContext dbcontext) { _configuration = configuration; _scoretService = commonService; _dbcontext = dbcontext; }