Пример #1
0
        //add manytomany to db

        public static CourseTeacher BindTeacherToCourse(int teacherId, int courseId)
        {
            CoursesEntities db = new CoursesEntities();

            if (db.CourseTeachers.Where(p => p.TeacherId == teacherId && p.CourseId == courseId).Count() != 0)
            {
                return(null);
            }
            CourseTeacher newCourseTeacher = new CourseTeacher();

            newCourseTeacher.CourseId  = courseId;
            newCourseTeacher.TeacherId = teacherId;
            db.CourseTeachers.Add(newCourseTeacher);
            try
            {
                db.SaveChanges();
                db.Dispose();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException)
            {
                db.Dispose();
                return(null);
            }
            return(newCourseTeacher);
        }
Пример #2
0
        public static Student AddStudent(string name, int group, int schoolId)
        {
            CoursesEntities db = new CoursesEntities();

            if (db.Students.Where(p => p.Name == name && p.GroupN == group && p.SchoolId == schoolId).Count() != 0)
            {
                return(null);
            }
            Student newStudent = new Student();

            newStudent.Name     = name;
            newStudent.GroupN   = group;
            newStudent.SchoolId = schoolId;
            db.Students.Add(newStudent);
            try
            {
                db.SaveChanges();
                db.Dispose();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException)
            {
                db.Dispose();
                return(null);
            }
            return(newStudent);
        }
Пример #3
0
        public static Course AddCourse(int subjectId, int duration, decimal cost)
        {
            CoursesEntities db = new CoursesEntities();

            if (db.Courses.Where(p => p.SubjectId == subjectId && p.Duration == duration && p.Cost == cost).Count() != 0)
            {
                return(null);
            }
            Course newCourse = new Course();

            newCourse.SubjectId = subjectId;
            newCourse.Duration  = duration;
            newCourse.Cost      = cost;
            db.Courses.Add(newCourse);
            try
            {
                db.SaveChanges();
                db.Dispose();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException)
            {
                db.Dispose();
                return(null);
            }
            return(newCourse);
        }
Пример #4
0
        public static Subject EditSubject(int id, string name)
        {
            CoursesEntities db = new CoursesEntities();

            if (db.Subjects.Where(p => p.Name == name).Count() != 0)
            {
                return(null);
            }
            Subject subject = db.Subjects.Find(id);

            if (subject != null)
            {
                subject.Name = name;
                try
                {
                    db.SaveChanges();
                    db.Dispose();
                    return(subject);
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException)
                {
                    db.Dispose();
                    return(null);
                }
            }
            return(null);
        }
Пример #5
0
        //edit db

        public static Teacher EditTeacher(int id, string name)
        {
            CoursesEntities db = new CoursesEntities();

            if (db.Teachers.Where(p => p.Name == name).Count() != 0)
            {
                return(null);
            }
            Teacher teacher = db.Teachers.Find(id);

            if (teacher != null)
            {
                teacher.Name = name;
                try
                {
                    db.SaveChanges();
                    db.Dispose();
                    return(teacher);
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException)
                {
                    db.Dispose();
                    return(null);
                }
            }
            return(null);
        }
Пример #6
0
        public static Student EditStudent(int id, string name, int group, int schoolId)
        {
            CoursesEntities db = new CoursesEntities();

            if (db.Students.Where(p => p.Name == name && p.GroupN == group && p.SchoolId == schoolId).Count() != 0)
            {
                return(null);
            }
            Student student = db.Students.Find(id);

            if (student != null)
            {
                student.Name     = name;
                student.GroupN   = group;
                student.SchoolId = schoolId;
                try
                {
                    db.SaveChanges();
                    db.Dispose();
                    return(student);
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException)
                {
                    db.Dispose();
                    return(null);
                }
            }
            return(null);
        }
Пример #7
0
        public static Course EditCourse(int id, decimal cost, int duration, int subjectId)
        {
            CoursesEntities db = new CoursesEntities();

            if (db.Courses.Where(p => p.SubjectId == subjectId && p.Duration == duration && p.Cost == cost).Count() != 0)
            {
                return(null);
            }
            Course course = db.Courses.Find(id);

            if (course != null)
            {
                course.Cost      = cost;
                course.Duration  = duration;
                course.SubjectId = subjectId;
                try
                {
                    db.SaveChanges();
                    db.Dispose();
                    return(course);
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException)
                {
                    db.Dispose();
                    return(null);
                }
            }
            return(null);
        }
Пример #8
0
        public static Topic AddTopic(string name, int courseId)
        {
            CoursesEntities db = new CoursesEntities();

            if (db.Topics.Where(p => p.Name == name && p.CourseId == courseId).Count() != 0)
            {
                return(null);
            }
            Topic newTopic = new Topic();

            newTopic.Name     = name;
            newTopic.CourseId = courseId;
            db.Topics.Add(newTopic);
            try
            {
                db.SaveChanges();
                db.Dispose();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException)
            {
                db.Dispose();
                return(null);
            }
            return(newTopic);
        }
Пример #9
0
        public static School EditSchool(int id, string name)
        {
            CoursesEntities db = new CoursesEntities();

            if (db.Schools.Where(p => p.Name == name).Count() != 0)
            {
                return(null);
            }
            School school = db.Schools.Find(id);

            if (school != null)
            {
                school.Name = name;
                try
                {
                    db.SaveChanges();
                    db.Dispose();
                    return(school);
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException)
                {
                    db.Dispose();
                    return(null);
                }
            }
            return(null);
        }
Пример #10
0
        public static Topic EditTopic(int id, string name, int courseId)
        {
            CoursesEntities db = new CoursesEntities();

            if (db.Topics.Where(p => p.Name == name && p.CourseId == courseId).Count() != 0)
            {
                return(null);
            }
            Topic topic = db.Topics.Find(id);

            if (topic != null)
            {
                topic.Name     = name;
                topic.CourseId = courseId;
                try
                {
                    db.SaveChanges();
                    db.Dispose();
                    return(topic);
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException)
                {
                    db.Dispose();
                    return(null);
                }
            }
            return(null);
        }
Пример #11
0
        public static List <School> GetSchools()
        {
            CoursesEntities db  = new CoursesEntities();
            List <School>   res = db.Schools.ToList();

            db.Dispose();
            return(res);
        }
Пример #12
0
        public static List <Topic> GetTopics(int courseId)
        {
            CoursesEntities db  = new CoursesEntities();
            List <Topic>    res = db.Topics.Where(p => p.CourseId == courseId).ToList();

            db.Dispose();
            return(res);
        }
Пример #13
0
        public static List <CourseView> GetCourseViews()
        {
            CoursesEntities   db  = new CoursesEntities();
            List <CourseView> res = db.CourseViews.ToList();

            db.Dispose();
            return(res);
        }
Пример #14
0
        public static List <Subject> GetSubjects()
        {
            CoursesEntities db  = new CoursesEntities();
            List <Subject>  res = db.Subjects.ToList();

            db.Dispose();
            return(res);
        }
Пример #15
0
        public static List <CoursesTeachersView> GetCourseTeachersViews(int teacherId)
        {
            List <CoursesTeachersView> res;
            CoursesEntities            db = new CoursesEntities();

            res = new List <CoursesTeachersView>();
            db.CoursesTeachersViews.Where(p => p.TeacherId == teacherId).ToList().ForEach(p => res.Add(p));
            db.Dispose();
            return(res);
        }
Пример #16
0
        public static List <CoursesStudentsView> GetCourseStudentViews(int studentId)
        {
            List <CoursesStudentsView> res;
            CoursesEntities            db = new CoursesEntities();

            res = new List <CoursesStudentsView>();
            db.CoursesStudentsViews.Where(p => p.StudentId == studentId).ToList().ForEach(p => res.Add(p));
            db.Dispose();
            return(res);
        }
Пример #17
0
        public static Subject GetSubject(int id)
        {
            CoursesEntities db  = new CoursesEntities();
            Subject         res = db.Subjects.ToList().Find(p => p.Id == id);

            if (res != null)
            {
                res.Courses = res.Courses.ToList();
            }
            db.Dispose();
            return(res);
        }
Пример #18
0
        public static School GetSchool(int id)
        {
            CoursesEntities db  = new CoursesEntities();
            School          res = db.Schools.ToList().Find(p => p.Id == id);

            if (res != null)
            {
                res.Students = res.Students.ToList();
            }
            db.Dispose();
            return(res);
        }
Пример #19
0
        public static Teacher GetTeacher(int id)
        {
            CoursesEntities db  = new CoursesEntities();
            Teacher         res = db.Teachers.ToList().Find(p => p.Id == id);

            if (res != null)
            {
                res.CoursesTeachers = res.CoursesTeachers.ToList();
            }
            db.Dispose();
            return(res);
        }
Пример #20
0
        public static Topic GetTopic(int id)
        {
            CoursesEntities db  = new CoursesEntities();
            Topic           res = db.Topics.ToList().Find(p => p.Id == id);

            if (res != null)
            {
                res.Cours.ToString();
            }
            db.Dispose();
            return(res);
        }
Пример #21
0
        public static Student GetStudent(int id)
        {
            CoursesEntities db  = new CoursesEntities();
            Student         res = db.Students.ToList().Find(p => p.Id == id);

            if (res != null && res.School != null)
            {
                res.School.ToString();
            }
            db.Dispose();
            return(res);
        }
Пример #22
0
        public static bool DelSchool(int id)
        {
            CoursesEntities db     = new CoursesEntities();
            School          school = db.Schools.Find(id);

            if (school != null)
            {
                db.Schools.Remove(school);
                try
                {
                    db.SaveChanges();
                    db.Dispose();
                    return(true);
                }
                catch (Exception)
                {
                    db.Dispose();
                    return(false);
                }
            }
            return(false);
        }
Пример #23
0
        public static bool DelSubject(int id)
        {
            CoursesEntities db      = new CoursesEntities();
            Subject         subject = db.Subjects.Find(id);

            if (subject != null)
            {
                db.Subjects.Remove(subject);
                try
                {
                    db.SaveChanges();
                    db.Dispose();
                    return(true);
                }
                catch (Exception)
                {
                    db.Dispose();
                    return(false);
                }
            }
            return(false);
        }
Пример #24
0
        public static bool DelTopic(int id)
        {
            CoursesEntities db    = new CoursesEntities();
            Topic           topic = db.Topics.Find(id);

            if (topic != null)
            {
                db.Topics.Remove(topic);
                try
                {
                    db.SaveChanges();
                    db.Dispose();
                    return(true);
                }
                catch (Exception)
                {
                    db.Dispose();
                    return(false);
                }
            }
            return(false);
        }
Пример #25
0
        //delete manytomany from db

        public static bool DelBindTeacherToCourse(int id)
        {
            CoursesEntities db            = new CoursesEntities();
            CourseTeacher   courseTeacher = db.CourseTeachers.Find(id);

            if (courseTeacher != null)
            {
                db.CourseTeachers.Remove(courseTeacher);
                try
                {
                    db.SaveChanges();
                    db.Dispose();
                    return(true);
                }
                catch (Exception)
                {
                    db.Dispose();
                    return(false);
                }
            }
            return(false);
        }
Пример #26
0
        public static bool DelBindStudentToCourse(int id)
        {
            CoursesEntities db            = new CoursesEntities();
            CourseStudent   courseStudent = db.CourseStudents.Find(id);

            if (courseStudent != null)
            {
                db.CourseStudents.Remove(courseStudent);
                try
                {
                    db.SaveChanges();
                    db.Dispose();
                    return(true);
                }
                catch (Exception)
                {
                    db.Dispose();
                    return(false);
                }
            }
            return(false);
        }
Пример #27
0
        //edit manytomany db

        public static CourseStudent EditBindStudentToCourse(int id, bool isPaid, int?sertificateNumber)
        {
            CoursesEntities db            = new CoursesEntities();
            CourseStudent   courseStudent = db.CourseStudents.Find(id);

            if (courseStudent != null)
            {
                courseStudent.IsPaid            = isPaid;
                courseStudent.SertificateNumber = sertificateNumber;
                try
                {
                    db.SaveChanges();
                    db.Dispose();
                    return(courseStudent);
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException)
                {
                    db.Dispose();
                    return(null);
                }
            }
            return(null);
        }
Пример #28
0
        public static CourseStudent GetCourseStudent(int id)
        {
            CoursesEntities db  = new CoursesEntities();
            CourseStudent   res = db.CourseStudents.ToList().Find(p => p.Id == id);

            if (res != null)
            {
                res.Cours.ToString();
                res.Student.ToString();
            }

            db.Dispose();
            return(res);
        }
Пример #29
0
        public static CourseStudent BindStudentToCourse(int studentId, int courseId)
        {
            CoursesEntities db = new CoursesEntities();
            //if (db.CourseStudents.Where(p => p.StudentId == studentId && p.CourseId == courseId).Count() != 0)
            //    return null;
            CourseStudent newCourseStudent = new CourseStudent();

            newCourseStudent.CourseId  = courseId;
            newCourseStudent.StudentId = studentId;
            newCourseStudent.IsPaid    = false;
            db.CourseStudents.Add(newCourseStudent);
            try
            {
                db.SaveChanges();
                db.Dispose();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException)
            {
                db.Dispose();
                return(null);
            }
            return(newCourseStudent);
        }
Пример #30
0
        //get entity from db

        public static Course GetCourse(int id)
        {
            CoursesEntities db  = new CoursesEntities();
            Course          res = db.Courses.ToList().Find(p => p.Id == id);

            if (res != null)
            {
                res.Topics          = res.Topics.ToList();
                res.CoursesTeachers = res.CoursesTeachers.ToList();
                res.CoursesStudents = res.CoursesStudents.ToList();
                res.Subject.ToString();
            }
            db.Dispose();
            return(res);
        }