Exemplo n.º 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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
        public static Subject AddSubject(string name)
        {
            CoursesEntities db = new CoursesEntities();

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

            newSubject.Name = name;
            db.Subjects.Add(newSubject);
            try
            {
                db.SaveChanges();
                db.Dispose();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException)
            {
                db.Dispose();
                return(null);
            }
            return(newSubject);
        }
Exemplo n.º 19
0
        //add to db

        public static Teacher AddTeacher(string name)
        {
            CoursesEntities db = new CoursesEntities();

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

            newTeacher.Name = name;
            db.Teachers.Add(newTeacher);
            try
            {
                db.SaveChanges();
                db.Dispose();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException)
            {
                db.Dispose();
                return(null);
            }
            return(newTeacher);
        }