コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }