コード例 #1
0
        public static List <StudentCourse> getCourses()
        {
            List <StudentCourse> studentCourses = new List <StudentCourse>();
            CourseDbContext      db             = new CourseDbContext();

            studentCourses = db.courses.ToList();

            return(studentCourses);
        }
コード例 #2
0
        public static StudentCourse updateCourse(StudentCourse course)
        {
            CourseDbContext db = new CourseDbContext();

            db.Entry(course).State = EntityState.Modified;
            db.SaveChanges();

            return(course);
        }
コード例 #3
0
        public static StudentCourse getCourse(int id)
        {
            StudentCourse   course = new StudentCourse();
            CourseDbContext db     = new CourseDbContext();

            course = db.courses.Find(id);

            return(course);
        }
コード例 #4
0
        public static StudentCourse updateCourseSQL(StudentCourse course)
        {
            string sql = "UPDATE Course SET " +
                         " description = @description, " +
                         " cost = @cost, " +
                         " prerequisite = @prerequisite, " +
                         " modified_by = @modified_by, " +
                         " modified_date = @modified_date " +
                         " WHERE course_no = @course_no;";
            CourseDbContext     db        = new CourseDbContext();
            List <SqlParameter> sqlParams = new List <SqlParameter>();

            sqlParams.Add(new SqlParameter("@description", course.description));
            sqlParams.Add(new SqlParameter("@cost", course.cost));
            sqlParams.Add(new SqlParameter("@prerequisite", course.prerequisite));
            sqlParams.Add(new SqlParameter("@modified_by", course.modified_by));
            sqlParams.Add(new SqlParameter("@modified_date", course.modified_date));
            sqlParams.Add(new SqlParameter("@course_no", course.course_No));


            db.Database.ExecuteSqlCommand(sql, sqlParams.ToArray());

            return(course);
        }