Ejemplo n.º 1
0
        public IActionResult DeleteStudent(int id)
        {
            MockDbService  mock  = new MockDbService();
            List <Student> studs = mock.GetStudents().ToList();

            studs.Remove(studs.Find(s => s.IdStudent == id));

            return(Ok("Usuwanie ukonczone"));
        }
Ejemplo n.º 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)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMiddleware <MiddlewareLog>();

            app.Use(async(context, next) =>
            {
                if (!context.Request.Headers.ContainsKey("Index"))
                {
                    context.Response.StatusCode = StatusCodes.Status401Unauthorized;
                    await context.Response.WriteAsync("Podanie indexu studenta jest wymagane");
                    return;
                }


                var studentId = context.Request.Headers["index"].ToString();

                if (!MockDbService.StudentIdAuthorization(studentId))
                {
                    context.Response.StatusCode = StatusCodes.Status401Unauthorized;
                    await context.Response.WriteAsync("Odmowa Dostêpu - Brak studenta o podanym indeksie");
                    return;
                }

                await next();
            });

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Ejemplo n.º 3
0
        // 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();
            }

            app.Use(async(context, next) =>
            {
                if (!context.Request.Headers.ContainsKey("Index"))
                {
                    context.Response.StatusCode = StatusCodes.Status401Unauthorized;
                    await context.Response.WriteAsync("Brak indeksu");
                    return;
                }

                string index = context.Request.Headers["Index"].ToString();
                //check in db
                MockDbService dbService = new MockDbService();
                if (dbService.CheckIndex(index))
                {
                    context.Response.StatusCode = StatusCodes.Status401Unauthorized;
                    await context.Response.WriteAsync("Brak indeksu");
                    return;
                }
                await next();
            });

            app.UseMiddleware <LoggingMiddleware>();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseHttpsRedirection();
            //app.UseMvc();
        }
 public StudentsController(MockDbService db)
 {
     studentData = db;
 }