示例#1
0
        public IActionResult GetStudent()
        {
            /*var list = new List<Student>();
             *
             * using (SqlConnection con = new SqlConnection(conString))
             * using (SqlCommand com = new SqlCommand())
             * {
             *  com.Connection = con;
             *  com.CommandText = "select * from Student";
             *
             *  con.Open();
             *  SqlDataReader dr = com.ExecuteReader();
             *  while (dr.Read())
             *  {
             *      var st = new Student();
             *      st.IndexNumber = dr["IndexNumber"].ToString();
             *      st.FirstName = dr["FirstName"].ToString();
             *      st.LastName = dr["LastName"].ToString();
             *      list.Add(st);
             *  }
             *
             * }*/
            SqlServerDbService sql = new SqlServerDbService();

            return(Ok(sql.GetStudents()));
        }
        public IActionResult GetStudents(string index)
        {
            var sql    = new SqlServerDbService();
            var result = sql.GetStudent(index);

            if (result != null)
            {
                return(Ok(result));
            }

            return(NotFound("Index number does not exists!!!"));
        }
        public IActionResult GetStudents()
        {
            var sql    = new SqlServerDbService();
            var result = sql.GetStudents();

            if (result.Count() > 0)
            {
                return(Ok(result));
            }

            return(NotFound("Database is empty!!!"));
        }
示例#4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IStudentsDbService service)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseMiddleware <LoggingMiddleware>();

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

                string index = context.Response.Headers["Index"].ToString();

                //checking if database contains student

                var check = service.IsStudentNumberUnique(index);

                if (!check)
                {
                    context.Response.StatusCode = StatusCodes.Status404NotFound;
                    await context.Response.WriteAsync("Student not found.");
                    return;
                }

                await next();
            });

            app.UseRouting();

            app.UseAuthorization();

            app.Use(async(context, next) =>
            {
                IStudentsDbService _dbService = new SqlServerDbService();
                _dbService.IsStudentNumberUnique(context.Response.Headers["Index"].ToString());
                await next();
            });

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
示例#5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IDbService idb)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseMiddleware <LoggingMiddleware>();
            app.Use(async(context, next) => {
                if (!context.Request.Headers.ContainsKey("Index"))
                {
                    context.Response.StatusCode = StatusCodes.Status401Unauthorized;
                    await context.Response.WriteAsync("Nie podano indeksu w nagłówku");
                    return;
                }
                var index = context.Request.Headers["Index"].ToString();

                IStudentsDbService dbService = new SqlServerDbService();
                if (!dbService.CheckIndex(index))
                {
                    context.Response.StatusCode = StatusCodes.Status401Unauthorized;
                    await context.Response.WriteAsync("Nie ma takiego studenta w bazie");
                    return;
                }
                await next();
            });
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

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

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
示例#6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IDbService idb)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseMiddleware <LoggingMiddleware>();

            app.Use(async(context, next) =>
            {
                if (!context.Request.Headers.ContainsKey("Index"))
                {
                    context.Response.StatusCode = StatusCodes.Status401Unauthorized;
                    await context.Response.WriteAsync("The index  number was not provided");
                    return;
                }

                //check if student is indexer the db//
                string index = context.Request.Headers["Index"].ToString();


                //open new sql connection
                SqlServerDbService s = new SqlServerDbService();


                if (idb.CheckIndex(index) == false)
                {
                    context.Response.StatusCode = StatusCodes.Status400BadRequest;
                    await context.Response.WriteAsync("Invalid student number");
                    return;
                }


                //the student is in db and validated
                await next();
            });
            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
示例#7
0
文件: Startup.cs 项目: s19048/cw3
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IStudentsDbService service)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            ;
            app.UseSwagger();
            app.UseSwaggerUI(config =>
            {
                config.SwaggerEndpoint("/swagger/v1/swagger.json", "Students App API");
            });

            //........... middleware uwierzytelnienie

            app.UseMiddleware <LoggingMiddleware>();
            app.Use(async(context, next) => {
                if (!context.Request.Headers.ContainsKey("Index"))
                {
                    context.Response.StatusCode = StatusCodes.Status401Unauthorized;
                    await context.Response.WriteAsync("Nie podano indeksu w nagłówku");
                    return;
                }
                var index = context.Request.Headers["Index"].ToString();

                IStudentsDbService dbService = new SqlServerDbService();
                if (!dbService.CheckIndex(index))
                {
                    await context.Response.WriteAsync("Nie ma takiego studenta w bazie");
                    return;
                }
                await next();
            });
            app.UseHttpsRedirection();
            app.UseRouting();
            app.UseAuthentication(); //--
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
示例#8
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 <LoggingMiddleware>();

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

                string IndexNumber    = context.Request.Headers["Index"].ToString();
                SqlServerDbService db = (SqlServerDbService)app.ApplicationServices.GetService(typeof(SqlServerDbService));
                if (!db.StudentExists(IndexNumber))
                {
                    context.Response.StatusCode = StatusCodes.Status401Unauthorized;
                    await context.Response.WriteAsync("Student o indexie podanym w nagłówku nie istnieje w bazie");
                    return;
                }

                await next();
            });


            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
        }
示例#9
0
 public EnrollmentsController(SqlServerDbService service)
 {
     _service = service;
 }
示例#10
0
 public StudentsController()
 {
     service = new SqlServerDbService();
 }
示例#11
0
 public EnrollmentsController(SqlServerDbService dbservice)
 {
     this.dbservice = dbservice;
 }
示例#12
0
 public StudentsController(SqlServerDbService dbService, IConfiguration configuration)
 {
     _dbService     = dbService;
     _configuration = configuration;
 }
 public EnrollmentsController(SqlServerDbService db)
 {
     this.db = db;
 }
示例#14
0
 public EnrollmentController(SqlServerDbService db)
 {
     dbService = db;
 }
示例#15
0
 public SecurityController(SqlServerDbService db, SecurityService security)
 {
     _db       = db;
     _security = security;
 }