public StudentWithSchoolList GetStudents(PaginationParameters paginationParameters) { SqlCommand command = _dbConnection.CreateProcedureCommand("GetStudents"); FillGetStudentsParameters(command, paginationParameters); using (IDataReader reader = command.ExecuteReader()) { if (!reader.Read()) { throw new Exception("Can't read page count"); } int pageCount = reader.GetInt32(0); int pageSize = reader.GetInt32(1); int pageNumber = reader.GetInt32(2); PaginationInfo paginationInfo = new PaginationInfo(pageCount, pageSize, pageNumber); reader.NextResult(); List <StudentWithSchool> students = new List <StudentWithSchool>(); while (reader.Read()) { StudentWithSchool student = ReadStudent(reader); students.Add(student); } return(new StudentWithSchoolList(students.ToArray(), paginationInfo)); } }
public StudentWithSchool GetStudent(int id) { SqlCommand command = _dbConnection.CreateProcedureCommand("GetStudent"); FillStudentIdParameters(command, id); using (IDataReader reader = command.ExecuteReader()) { if (!reader.Read()) { throw new Exception($"Student not found. Student id: [{id}]"); } StudentWithSchool student = ReadStudent(reader); return(student); } }