コード例 #1
0
 public MssqlDbAuthenticationService(IConfiguration configuration, IDbStudentService dbStudentService,
                                     IEncryptionService encryptionService)
 {
     _configuration     = configuration;
     _dbStudentService  = dbStudentService;
     _encryptionService = encryptionService;
 }
コード例 #2
0
        // 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(); });
        }
コード例 #3
0
 public StudentController(IDbStudentService context)
 {
     _context = context;
 }
コード例 #4
0
ファイル: StudentsController.cs プロジェクト: s18277/cw4
 public StudentsController(IDbStudentService dbService)
 {
     _dbService = dbService;
 }
コード例 #5
0
ファイル: PromotionsController.cs プロジェクト: s18277/cw5
 public PromotionsController(IDbStudentService dbService)
 {
     _dbService = dbService;
 }