static public Student GetStudentDataByUser(User user) { //int[] array = new int[2]; //array[0] = 5; //array[1] = 3; //for (int i = 0; i < 2; i++) //{ // Console.WriteLine(array[i]); //} //foreach (int num in array) //{ // Console.WriteLine(num); //} //foreach (Student st in StudentData.TestStudent) //{ // if (user.FacNum == st.FacNum) // { // return st; // } //} //return null; StudentInfoContext context = new StudentInfoContext(); Student result = (from st in context.Students where st.FacNum == user.FacNum select st).First(); return(result); }
public MainWindow() { InitializeComponent(); FillStudStatusChoices(); DataContext = this; context = new StudentInfoContext(); }
public bool TestStudentsUsersIfEmpty() { bool emptyUserOrStudentTb = true; StudentInfoContext context = new StudentInfoContext(); IEnumerable <Student> queryStudents = context.Students; IEnumerable <User> queryUsers = context.Users; int countUsers = queryUsers.Count(); int countStudents = queryStudents.Count(); if (countUsers == 0) { CopyTestUsers(); } else { emptyUserOrStudentTb = false; } if (countStudents == 0) { CopyTestStudents(); } else { emptyUserOrStudentTb = false; } return(emptyUserOrStudentTb); }
private static List <Student> GetRegions() { StudentInfoContext context = new StudentInfoContext(); List <Student> students = context.Students.ToList(); return(students); }
private void OnClick_Login(object sender, RoutedEventArgs e) { try { string username = txtUsername.Text; string password = boxPassword.Password; AssertValidUserCredentials(username, password); StudentInfoContext context = new StudentInfoContext(); User user = DatabaseUtils.GetUserByUsername(username); if (UserRoles.ADMIN.Equals(user.Role)) { AdminWindow adminWindow = new AdminWindow(); adminWindow.Show(); } else { LoginUser(); } } catch (InvalidOperationException) { MessageBox.Show(String.Format("Потребител с име: {0} не беше намерен.", txtUsername.Text)); } catch (Exception exception) { MessageBox.Show(exception.Message); } }
/* private static void ResetTestUserData() * { * if (TestUsersIfEmpty()) * { * CreateUsers(); * foreach (User user in _TestUsers) * { * dbContext.Users.Add(user); * } * dbContext.SaveChanges(); * } * } * * static private void CreateUsers() * { * _TestUsers = new List<User>(); * _TestUsers.Add(new User("Pastrashko", "zlato0", "121214666", 1, DateTime.Now, DateTime.Now.AddYears(5))); * _TestUsers.Add(new User("Dragan", "nodiggity", "121219088", 4, DateTime.Now, DateTime.Now.AddYears(1))); * _TestUsers.Add(new User("Mustakan", "qwerty1", "121219089", 4, DateTime.Now, DateTime.Now.AddYears(-2))); * }*/ public static Student IsThereStudent(String number) { StudentInfoContext context = new StudentInfoContext(); Student result = (from st in context.Students where st.facNumber == number select st).First(); return(result); }
private void SaveStudentsInTable(StudentInfoContext context) { foreach (Student st in StudentData.DefaultStudents) { context.Students.Add(st); } context.SaveChanges(); }
private void SaveUsersInTable(StudentInfoContext context) { foreach (User user in UserData.TestUsers) { context.Users.Add(user); } context.SaveChanges(); }
private bool TestStudentsIfEmpty() { StudentInfoContext context = new StudentInfoContext(); IEnumerable <Student> queryStudents = context.Students; return(false); }
public static Student IsThereStudent(string facNum) { StudentInfoContext context = new StudentInfoContext(); return((from st in context.Students where st.FacultyNumber == facNum select st).First()); }
public bool TestStudentsIfEmpty() { StudentInfoContext context = new StudentInfoContext(); IEnumerable <Student> queryStudents = context.Students; int countStudents = queryStudents.Count(); return(countStudents == 0 ? true : false); }
public static Student IsThereStudent(User userToCheck) { StudentInfoContext context = new StudentInfoContext(); Student result = (from st in context.Students where st.facultyNumber == userToCheck.facultyNumber select st).First(); return(result); //return null; // if it gets here that means no such student is found and the function will return null }
private void loginButton_Click(object sender, RoutedEventArgs e) { StudentInfoContext context = new StudentInfoContext(); IEnumerable <User> Users = context.Users; if (loginButton.Content.Equals("Провери")) { if (UserData.AllUsersUsernames().ContainsKey(loginTB.Text)) { user = Users.ElementAt(UserData.AllUsersUsernames()[loginTB.Text]); infoLabel.Content = "Потребител " + user.username; loginLable.Content = "Парола:"; loginTB.Clear(); loginButton.Content = "Влез"; } else { infoLabel.Content = "Невалиден потребител"; loginTB.Text = ""; } } else if (loginButton.Content.Equals("Влез")) { if (user.password.Equals(loginTB.Text)) { infoLabel.Content = "Влязъл Потребител " + user.username; loginLable.Content = ""; loginTB.Clear(); loginTB.IsEnabled = false; loginButton.Content = "Излез"; loadFunctionalitiesAccordingRole(); //context.Logger.Add(new Logs("User " + user.username + " logged")); //context.SaveChanges(); } else { user = anonymousUser; infoLabel.Content = "Невалидна парола"; loginLable.Content = "Потр. име:"; loginTB.Clear(); loginButton.Content = "Провери"; } } else if (loginButton.Content.Equals("Излез")) { user = anonymousUser; infoLabel.Content = ""; loginLable.Content = "Потр. име:"; loginButton.Content = "Провери"; DisableTextBoxes(); ClearTextBoxes(); loginTB.IsEnabled = true; studentButton.Visibility = Visibility.Hidden; createStudentButton.Visibility = Visibility.Hidden; } }
public static void insertIntoStudentAndGrades() { StudentInfoContext context = new StudentInfoContext(); foreach (Student student in getAllStudents(context)) { context.Students.Add(student); } context.SaveChanges(); }
public static List <Student> getAllStudents(StudentInfoContext context) { students = new List <Student>(); List <DisciplineGrade> grades = setAllDisciplineGrades(context); students.Add(new Student("Ivan", "Ivanov", "Ivanov", "FKSU", "KSI", "bachelor", Status.CERTIFIED, "121217033", 3, 9, 36, grades)); // students.Add(new Student(2, "Dragan", "Draganov", "Ivanov", "FKSU", "KSI", "bachelor", Status.CERTIFIED, "1212234567", 3, 9, 36, grades)); return(students); }
void CopyTestUsers() { StudentInfoContext context = new StudentInfoContext(); foreach (User u in UserData.TestUsers) { context.Users.Add(u); } context.SaveChanges(); }
void CopyTestStudents() { StudentInfoContext context = new StudentInfoContext(); foreach (Student st in StudentData.TestStudents) { context.Students.Add(st); } context.SaveChanges(); }
public Student IsThereStudent() { User user1 = new User(); StudentInfoContext context = new StudentInfoContext(); Student result = (from st in context.Students where st.number == user1.number select st).First(); return(result); }
private bool TestStudentsIfEmpty() { StudentInfoContext context = new StudentInfoContext(); IEnumerable <Student> queryStudents = context.Students; int countStudents = queryStudents.Count(); if (countStudents == 0) { return(true); } return(false); }
private bool TestUsersIfEmpty() { StudentInfoContext context = new StudentInfoContext(); IEnumerable <User> queryUsers = context.Users; int countUsers = queryUsers.Count(); if (countUsers == 0) { return(true); } return(false); }
private Boolean IsUserTableEmtpy(StudentInfoContext context) { IEnumerable <User> queryUsers = context.Users; if (queryUsers.Count() == 0) { return(true); } else { return(false); } }
private Boolean IsStudentsTableEmtpy(StudentInfoContext context) { IEnumerable <Student> queryStudents = context.Students; if (queryStudents.Count() == 0) { return(true); } else { return(false); } }
public static void CopyTestStudents() { StudentInfoContext context = new StudentInfoContext(); foreach (Student us in TestStudents) { context.Students.Add(us); } context.SaveChanges(); }
private void TestStudentCount(object sender, RoutedEventArgs e) { StudentInfoContext stInfCont = new StudentInfoContext(); bool areThereAnySt_Us = stInfCont.TestStudentsUsersIfEmpty(); if (areThereAnySt_Us) { MessageBox.Show("True"); } else { MessageBox.Show("False"); } }
//StudentInfoContext context = new StudentInfoContext(); public bool TestStudentsIfEmpty() { StudentInfoContext context = new StudentInfoContext(); IEnumerable <Student> quertyStudents = context.Students; int?countStudents = quertyStudents.Count(); if (quertyStudents == null) { return(true); } else { return(false); } }
public static Student GetStudentByFaculty(string facultyNumber) { if (String.IsNullOrEmpty(facultyNumber)) { throw new ArgumentException("Не е въведен факултетен номер!"); } StudentInfoContext context = new StudentInfoContext(); Student result = (from st in context.Students where st.FacultyNumber == facultyNumber select st).First(); return(result); }
private void InsertSpecializationExamples() { string[] specializations = { "Computer science", "Engineering", "Driver", "Chef", "Manager" }; StudentInfoContext context = new StudentInfoContext(); int i = 1; foreach (string specialization in specializations) { context.Specializations.Add(new Specialization(i, specialization)); i++; } context.SaveChanges(); }
private void OnClick_Save(object sender, RoutedEventArgs e) { try { StudentInfoContext context = new StudentInfoContext(); DbSet <User> usersTable = context.Users; string username = txtUsername.Text; if (DatabaseUtils.IsUserPresent(username)) { throw new Exception("Потребител с това потребителско име вече съществува!"); } string password = boxPassword.Password; string role = boxRole.Text; usersTable.Add(new User(username, password, role, DateTime.Now, DateTime.Now.AddYears(1))); if (UserRoles.STUDENT.Equals(role)) { string name = txtName.Text; string surname = txtSurname.Text; string lastName = txtLastName.Text; string faculty = boxFaculty.Text; string specialty = boxSpecialty.Text; string degree = boxDegree.Text; string status = boxStatus.Text; string facultyNumber = txtFacultyNumber.Text; int course = int.Parse(txtCourse.Text); int flow = int.Parse(txtFlow.Text); int group = int.Parse(txtGroup.Text); context.Students.Add(new Student(name, surname, lastName, faculty, specialty, degree, status, facultyNumber, course, flow, group)); } context.SaveChanges(); MessageBox.Show("Записано успешно!"); ResetInputControls(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public MainPage() { InitializeComponent(); DisableTextBoxes(); loginTB.IsEnabled = true; studentButton.Visibility = Visibility.Hidden; createStudentButton.Visibility = Visibility.Hidden; FillStudStatusChoices(); this.DataContext = this; StudentInfoContext context = new StudentInfoContext(); if (IsStudentsTableEmtpy(context)) { SaveStudentsInTable(context); } if (IsUserTableEmtpy(context)) { SaveUsersInTable(context); } }
public static List <DisciplineGrade> setAllDisciplineGrades(StudentInfoContext context) { List <DisciplineGrade> grades = new List <DisciplineGrade>(); grades.Add(new DisciplineGrade("English 1", FormOfControl.NOT_AVAILABLE, 6, DateTime.Now, 1, 1)); grades.Add(new DisciplineGrade("Mathematics 1", FormOfControl.EXAM, 5, DateTime.Now, 1, 1)); grades.Add(new DisciplineGrade("Iconomics", FormOfControl.ONGOING_ASSESSMENT, 4, DateTime.Now, 1, 1)); grades.Add(new DisciplineGrade("OIP", FormOfControl.ONGOING_ASSESSMENT, 3, DateTime.Now, 1, 1)); grades.Add(new DisciplineGrade("Programing C", FormOfControl.EXAM, 6, DateTime.Now, 1, 1)); grades.Add(new DisciplineGrade("Fizics", FormOfControl.EXAM, 2, DateTime.Now, 1, 1)); grades.Add(new DisciplineGrade("Chemistry", FormOfControl.ONGOING_ASSESSMENT, 6, DateTime.Now, 1, 1)); foreach (DisciplineGrade grade in grades) { context.DisciplineGrades.Add(grade); } return(grades); }