Beispiel #1
0
        //public IStudentEntity GetStudentById(int studentId)
        public async Task <IStudentEntity> GetStudentById(int studentId)
        {
            if (studentId <= 0)
            {
                return(null);
            }

            using (var dataTransfer = StudentDbService.FetchStudentByStudentId(studentId))
            {
                if (dataTransfer.Table.Rows.Count > 0)
                {
                    foreach (DataRow row in dataTransfer.Table.Rows)
                    {
                        var temp = new StudentEntity
                        {
                            StudentId         = int.Parse(row["StudentId"].ToString(), CultureInfo.InvariantCulture),
                            StudentName       = row["StudentName"].ToString(),
                            StudentRollNumber = row["StudentRollNumber"].ToString(),
                            StudentFatherName = row["StudentFatherName"].ToString(),
                            StudentMotherName = row["StudentMotherName"].ToString()
                        };

                        return(temp);
                    }
                }
            }

            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Get All students
        /// </summary>
        /// <returns>Student List</returns>
        //public async Task<IList<IStudentEntity>> GetAllStudentList()
        public async Task <List <IStudentEntity> > GetAllStudentList()
        {
            List <IStudentEntity> studentEntities = new List <IStudentEntity>();

            using (var dataTransfer = StudentDbService.FetchAllStudents())
            {
                if (dataTransfer.Table.Rows.Count > 0)
                {
                    foreach (DataRow row in dataTransfer.Table.Rows)
                    {
                        var temp = new StudentEntity
                        {
                            StudentId         = int.Parse(row["StudentId"].ToString(), CultureInfo.InvariantCulture),
                            StudentName       = row["StudentName"].ToString(),
                            StudentRollNumber = row["StudentRollNumber"].ToString(),
                            StudentFatherName = row["StudentFatherName"].ToString(),
                            StudentMotherName = row["StudentMotherName"].ToString()
                        };

                        studentEntities.Add(temp);
                    }
                }
            }
            return(studentEntities);
        }
Beispiel #3
0
        /// <summary>
        /// Get AllStudentList With Paging Sorting
        /// </summary>
        /// <param name="searchValue">searchValue</param>
        /// <param name="pageNo">page No</param>
        /// <param name="pageSize">page Size</param>
        /// <param name="sortColumn">sort Column</param>
        /// <param name="sortOrder">sort Order</param>
        /// <returns>Student data table</returns>
        public List <IStudentEntity> GetAllStudentListWithPaging_Sorting(string searchValue, int pageNo, int pageSize, string sortColumn, string sortOrder)
        {
            List <IStudentEntity> studentEntities = new List <IStudentEntity>();

            using (var dataTransfer = StudentDbService.FetchAllStudents())
            {
                if (dataTransfer.Table.Rows.Count > 0)
                {
                    foreach (DataRow row in dataTransfer.Table.Rows)
                    {
                        var temp = new StudentEntity
                        {
                            StudentId         = int.Parse(row["StudentId"].ToString(), CultureInfo.InvariantCulture),
                            StudentName       = row["StudentName"].ToString(),
                            StudentRollNumber = row["StudentRollNumber"].ToString(),
                            StudentFatherName = row["StudentFatherName"].ToString(),
                            StudentMotherName = row["StudentMotherName"].ToString()
                        };

                        studentEntities.Add(temp);
                    }
                }
            }
            return(studentEntities);
        }
Beispiel #4
0
        public IActionResult RefreshToken(string token)
        {
            Student student = StudentDbService.CheckRefToken(token);

            if (student == null)
            {
                return(BadRequest());
            }
            return(Login(new LoginRequest(student.IndexNumber, student.password)));
        }
Beispiel #5
0
        private void RemoveButton_Click(object sender, RoutedEventArgs e)
        {
            //Check user decision
            if (StudentsDataGrid.SelectedItems.Count > 0)
            {
                var messageBoxResult = MessageBox.Show("Czy na pewno chcesz usunąć dane studentów?", "Deleting Students", MessageBoxButton.OKCancel, MessageBoxImage.Question);
                if (messageBoxResult == MessageBoxResult.OK)
                {
                    //Prepare list to remove
                    var listOfStudentsToRemove = StudentsDataGrid.SelectedItems;
                    var listOfIdToRemove       = new List <int>();
                    foreach (Student s in listOfStudentsToRemove)
                    {
                        listOfIdToRemove.Add(s.Id);
                    }

                    //Remove from DB

                    var areStudentsRemoved = StudentDbService.RemoveFromDb(listOfIdToRemove);

                    //If succeeded, remove from DataGrid
                    if (areStudentsRemoved)
                    {
                        Student student;
                        for (int ii = Student._ListaStudentow.Count - 1; ii >= 0; ii--)
                        {
                            student = Student._ListaStudentow.ElementAt(ii);
                            if (listOfIdToRemove.Contains(student.Id))
                            {
                                Student._ListaStudentow.Remove(student);
                            }
                        }
                        if (listOfIdToRemove.Count == 1)
                        {
                            MessageBox.Show("Usunięto studenta", "DeansOffice", MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                        else
                        {
                            MessageBox.Show("Usunięto studentów", "DeansOffice", MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Nie wybrano studentów", "DeansOffice", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Beispiel #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)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseMiddleware <LoggingMiddleware>();

            /* app.UseSwagger();
             * app.UseSwaggerUI(
             *   config => {
             *       config.SwaggerEndpoint("/swagger/v1/swagger.json", "My API");
             *   });*/
            app.Use(async(context, next) => {
                if (!context.Request.Headers.ContainsKey("Index"))
                {
                    context.Response.StatusCode = StatusCodes.Status401Unauthorized;
                    await context.Response.WriteAsync("ERROR [Middleware]: Nie podano numeru indexu");
                    return;
                }

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

                StudentDbService trueStudent = new StudentDbService();

                if (!trueStudent.trueStudent(index))
                {
                    context.Response.StatusCode = StatusCodes.Status404NotFound;
                    await context.Response.WriteAsync("Brak indexu w bazie");
                    return;
                }
                await next();
            });



            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Beispiel #7
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            var wnd = new DeansOffice();

            wnd.ShowDialog();
            ResetSubjects();
            if (wnd.NewStudent != null)
            {
                var newStudent     = wnd.NewStudent;
                var isStudentAdded = StudentDbService.AddRecordToDb(newStudent);
                if (isStudentAdded)
                {
                    Student._ListaStudentow.Add(newStudent);
                    MessageBox.Show("Dodano studenta", "DeansOffice", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
        }
Beispiel #8
0
        public IActionResult Login(LoginRequest request)
        {
            Student student = StudentDbService.GetStudent(request.Login);

            //Console.WriteLine(PasswordHelper.CreateSecretValue(student.password, student.salt));
            if (!PasswordHelper.Validate(request.Haslo, student.salt, student.password))
            {
                return(BadRequest("Błędne hasło"));
            }

            var claims = new[]
            {
                new Claim(ClaimTypes.NameIdentifier, student.IndexNumber),
                new Claim(ClaimTypes.Name, student.FirstName),
                new Claim(ClaimTypes.Surname, student.LastName),
                new Claim(ClaimTypes.DateOfBirth, student.BirthDate.ToString()),
                new Claim(ClaimTypes.Role, "employee")
            };

            var key    = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["SecretKey"]));
            var creeds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);

            var token = new JwtSecurityToken
                        (
                issuer: "Gakko",
                audience: "Students",
                claims: claims,
                expires: DateTime.Now.AddMinutes(5),
                signingCredentials: creeds
                        );

            var      refreshToken = Guid.NewGuid();
            DateTime dateTime     = DateTime.Now;

            StudentDbService.AddRefreshToken(student, refreshToken.ToString(), dateTime.AddDays(1));

            return(Ok(new
            {
                token = new JwtSecurityTokenHandler().WriteToken(token),
                refreshToken
            }));
        }
Beispiel #9
0
        private void DataGridRow_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            var student = (Student)StudentsDataGrid.SelectedItem;
            var wnd     = new DeansOffice(student);

            wnd.ShowDialog();
            if (wnd.NewStudent != null)
            {
                var editedStudent    = wnd.NewStudent;
                var isStudentUpdated = StudentDbService.EditRecordInDb(student, editedStudent);
                if (isStudentUpdated)
                {
                    var orginalStudent = Student._ListaStudentow.First(s => s.Id == student.Id);
                    UpdateStudentDataInListaStudentow(orginalStudent, editedStudent);
                    MessageBox.Show("Uaktualniono dane studenta", "DeansOffice", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            ResetSubjects();
            //Student._ListaStudentow = StudentDbService.PullStudentsFromDbToList();
        }
Beispiel #10
0
 public StudentsController(StudentDbService dbService, IConfiguration configuration)
 {
     _dbService    = dbService;
     Configuration = configuration;
 }
Beispiel #11
0
        /// <summary>
        /// Create Student
        /// </summary>
        /// <param name="studentEntity">Student Entity</param>
        /// <returns>Entity Id</returns>
        //public int CreateStudent(IStudentEntity studentEntity)
        public async Task <IStudentEntity> CreateStudent(IStudentEntity studentEntity)
        {
            var result = StudentDbService.InsertUpdate(studentEntity);

            return(result);
        }
Beispiel #12
0
 private void GetDataFromDb()
 {
     Studies._StudiesList    = StudentDbService.PullStudiesFromDB();
     Subject._SubjectList    = StudentDbService.PullSubjectsFromDB();
     Student._ListaStudentow = StudentDbService.PullStudentsFromDbToList();
 }