public StudentInformationDAL GetStudentByStudentName(string studentName) { List <StudentInformationDAL> students = new List <StudentInformationDAL>(); StudentInformationDAL student; string cs = ConfigurationManager.ConnectionStrings["TeamB"].ConnectionString; using (SqlConnection connection = new SqlConnection(cs)) { connection.Open(); //Deschidere conexiune SqlCommand command = new SqlCommand(); command.CommandText = "spGetStudentByUserName"; command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@Name", studentName); command.Connection = connection; using (var reader = command.ExecuteReader()) { while (reader.Read()) { student = new StudentInformationDAL() { StudentID = reader.GetInt32(reader.GetOrdinal("StudentID")), Email = reader["Email"].ToString(), StudentName = reader["UserName"].ToString() }; students.Add(student); } } } return(students.FirstOrDefault()); }
public StudentInformationBL GetStudentByStudentName(string studentName) { StudentRepository repository = new StudentRepository(); StudentInformationDAL newStudent = repository.GetStudentByStudentName(studentName); StudentInformationBL student = new StudentInformationBL() { StudentID = newStudent.StudentID, Email = newStudent.Email, StudentName = newStudent.StudentName }; return(student); }