Exemplo n.º 1
0
        public ActionResult Create(Course_Ent course_Ent, string TeacherName)
        {
            Course_DAL course_DAL = new Course_DAL();

            //Teacher_DAL teacher_DAL = new Teacher_DAL();

            if (!course_DAL.Check_Exist(course_Ent.CourseID))
            {
                Teacher_DAL teacher_DAL = new Teacher_DAL();
                ViewBag.Teachers = teacher_DAL.GetTeachers();
                ViewBag.Message  = "ID Tồn Tại !";
                return(View());
            }

            Teacher_Ent teacher = new Teacher_Ent();

            teacher.TeacherID = int.Parse(TeacherName);
            //teacher.TeacherName = teacher_DAL.GetName(teacher.TeacherID);

            course_Ent.Teacher = teacher;

            if (!(course_DAL.Add_Course(course_Ent)))
            {
                Teacher_DAL teacher_DAL = new Teacher_DAL();
                ViewBag.Teachers = teacher_DAL.GetTeachers();
                ViewBag.Message  = "Có Lỗi Xảy Ra !";
                return(View());
            }

            return(RedirectToAction("Course", "Course"));
        }
Exemplo n.º 2
0
        public Course_Ent GetCourse_Ent(int id)
        {
            Course      course      = db.Courses.Where(c => c.CourseID == id).FirstOrDefault();
            Course_Ent  course_Ent  = new Course_Ent();
            Teacher_DAL teacher_DAL = new Teacher_DAL();
            Teacher_Ent teacher_Ent = new Teacher_Ent();

            course_Ent.CourseID     = course.CourseID;
            course_Ent.CourseName   = course.CourseName;
            course_Ent.Location     = course.Location;
            teacher_Ent.TeacherID   = course.TeacherID;
            teacher_Ent.TeacherName = teacher_DAL.GetName(course.TeacherID);
            course_Ent.Teacher      = teacher_Ent;

            return(course_Ent);
        }
Exemplo n.º 3
0
        public Boolean Add_Course(Course_Ent course_Ent)
        {
            try
            {
                Course course = new Course();
                course.CourseID   = course_Ent.CourseID;
                course.CourseName = course_Ent.CourseName;
                course.Location   = course_Ent.Location;
                course.TeacherID  = course_Ent.Teacher.TeacherID;

                db.Courses.Add(course);
                db.SaveChanges();
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
        public ActionResult Edit(Course_Ent course_Ent, string TeacherName)
        {
            Course_DAL course_DAL = new Course_DAL();
            //Teacher_DAL teacher_DAL = new Teacher_DAL();

            Teacher_Ent teacher = new Teacher_Ent();

            teacher.TeacherID = int.Parse(TeacherName);
            //teacher.TeacherName = teacher_DAL.GetName(teacher.TeacherID);

            course_Ent.Teacher = teacher;

            if (!(course_DAL.Edit(course_Ent)))
            {
                Teacher_DAL teacher_DAL = new Teacher_DAL();
                ViewBag.Teachers = teacher_DAL.GetTeachers();
                ViewBag.Message  = "Có Lỗi Xảy Ra !";
                return(View());
            }

            return(RedirectToAction("Course", "Course"));
        }
Exemplo n.º 5
0
        public List <Course_Ent> GetCourses()
        {
            Teacher_DAL       teacher_DAL = new Teacher_DAL();
            List <Course_Ent> courses     = new List <Course_Ent>();

            foreach (Course course in db.Courses.ToList())
            {
                Course_Ent course_ent = new Course_Ent();

                course_ent.CourseID   = course.CourseID;
                course_ent.CourseName = course.CourseName;
                course_ent.Location   = course.Location;

                Teacher_Ent teacher_Ent = new Teacher_Ent();
                teacher_Ent.TeacherID   = course.TeacherID;
                teacher_Ent.TeacherName = teacher_DAL.GetName(course.TeacherID);

                course_ent.Teacher = teacher_Ent;

                courses.Add(course_ent);
            }

            return(courses);
        }
Exemplo n.º 6
0
        public Boolean Edit(Course_Ent course_Ent)
        {
            Course course = db.Courses.Where(c => c.CourseID == course_Ent.CourseID).FirstOrDefault();

            if (course == null)
            {
                return(false);
            }

            try
            {
                course.CourseName = course_Ent.CourseName;
                course.Location   = course_Ent.Location;
                course.TeacherID  = course_Ent.Teacher.TeacherID;

                db.SaveChanges();
            }
            catch
            {
                return(false);
            }

            return(true);
        }