private void buttonLogin_Click(object sender, RoutedEventArgs e) { var login = textBoxLogin.Text; var password = Other.Hashing.Encryptor.GetMD5Hash(textBoxPassword.Text); using (StudentRankingSystemContext db = new StudentRankingSystemContext()) { var users = db.Users; foreach (var u in users) { // MessageBox.Show(u.Login.ToString() + $" {u.Password} "); } foreach (var s in db.Scores) { // MessageBox.Show(s.ScoreId.ToString() + $"{s.CourseId}, { s.FinalScore}, {s.StudentId} "); } User user = users.Where(u => (u.Login == login) && (u.Password == password)).Select(u => u).SingleOrDefault <User>(); if (user == null) { MessageBox.Show(this, "Invalid user name or password", "Authentication Error"); } else { DialogResult = true; } } }
public ICollection GetStudentsData() { using (StudentRankingSystemContext context = new StudentRankingSystemContext()) { var studentsData = context.Students.Select(s => new { StudentName = s.Name, StudentSurname = s.Surname }); return(studentsData.ToList()); } }
public ICollection GetAverageScores() { using (StudentRankingSystemContext context = new StudentRankingSystemContext()) { var studentsScores = from student in context.Students join score in context.Scores on student.StudentId equals score.StudentId select new { StudentID = student.StudentId, Score = score.FinalScore }; var averageScores = studentsScores.GroupBy(s => s.StudentID).Select (g => new { AverageScore = g.Average(s => s.Score), StudentID = g.Key }).ToList(); return(averageScores); } }
public ICollection GetAverageScores() { using (StudentRankingSystemContext context = new StudentRankingSystemContext()) { var studentsScores = from student in context.Students join score in context.Scores on student.StudentId equals score.StudentId select new { StudentID = student.StudentId, Score = score.FinalScore }; //Review BD: Hard to read this statement. //It would be better to use query syntax like in previous statement var averageScores = studentsScores.GroupBy(s => s.StudentID).Select (g => new { AverageScore = g.Average(s => s.Score), StudentID = g.Key }).ToList(); return(averageScores); } }