void IRepository.UpdateStudent(Models.Student model) { var parameters = new[] { new SqlParameter("@Id", model.Id), new SqlParameter("@TeacherClassId", model.ClassId), new SqlParameter("@StudentName", model.StudentName), new SqlParameter("@StudentDateOfBirth", model.StudentDateOfBirth), new SqlParameter("@Active", model.Active) }; using (var db = new Db(ConnectionString)) { db.CallProc(StoredProcedures.UpdateStudent, parameters); } }
Models.Student IRepository.CreateStudent(Models.Student model) { var parameters = new[] { new SqlParameter("@TeacherClassId", model.ClassId), new SqlParameter("@StudentName", model.StudentName), new SqlParameter("@StudentDateOfBirth", model.StudentDateOfBirth), new SqlParameter("@Active", 1) //Active when created }; using (var db = new Db(ConnectionString)) { model.Id = db.CallProcWithReturnValue(StoredProcedures.CreateStudent, parameters); } return(model); }
Models.Student IRepository.GetStudent(int id) { var result = new Models.Student(); var parameters = new[] { new SqlParameter("@Id", id) }; using (var db = new Db(ConnectionString)) { db.UseDataReader(StoredProcedures.GetStudent, parameters, reader => { while (reader.Read()) { result.Id = reader.GetInt("Id"); result.ClassId = reader.GetInt("TeacherClassId"); result.ClassName = reader.GetString("ClassName"); result.StudentDateOfBirth = reader.GetDateTime("StudentDateOfBirth"); result.StudentName = reader.GetString("StudentName"); result.Active = reader.GetBool("Active"); } }); } return(result); }