public MssqlDbAuthenticationService(IConfiguration configuration, IDbStudentService dbStudentService, IEncryptionService encryptionService) { _configuration = configuration; _dbStudentService = dbStudentService; _encryptionService = encryptionService; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IDbStudentService dbService) { app.UseMiddleware <ExceptionMiddleware>(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseSwagger(); app.UseSwaggerUI(options => { options.SwaggerEndpoint("/swagger/v1/swagger.json", "Students API"); }); // Logging middleware is enabled after Swagger one to avoid logging requests for documentation. app.UseMiddleware <LoggingMiddleware>(); app.Use(async(context, next) => { if (dbService.GetAllStudents().ToList().Count == 0) { await next(); return; } if (!context.Request.Headers.ContainsKey(IndexHeader)) { context.Response.StatusCode = StatusCodes.Status401Unauthorized; await context.Response.WriteAsync("Brak nagłówka z numerem indeksu!"); return; } var index = context.Request.Headers[IndexHeader].ToString(); if (dbService.GetStudent(index) == null) { context.Response.StatusCode = StatusCodes.Status404NotFound; await context.Response.WriteAsync("Przekazany numer indeksu nie istnieje w bazie danych!"); return; } await next(); }); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public StudentController(IDbStudentService context) { _context = context; }
public StudentsController(IDbStudentService dbService) { _dbService = dbService; }
public PromotionsController(IDbStudentService dbService) { _dbService = dbService; }