Exemple #1
0
        public void DeleteExamPeriod(int examPeriodId)
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                var findExamPeriod = dbContext.tblExamPeriods.Find(examPeriodId);

                if (dbContext.tblExams.Any(x => x.ExamPeriodId == examPeriodId))
                {
                    DeleteFault fault = new DeleteFault()
                    {
                        Result      = false,
                        Message     = "Unable to delete!",
                        Description = "Exam Period is referenced in Exam."
                    };

                    throw new FaultException <DeleteFault>(fault);
                }

                if (findExamPeriod != null)
                {
                    dbContext.tblExamPeriods.Remove(findExamPeriod);
                    dbContext.SaveChanges();
                }
            }
        }
Exemple #2
0
        public void DeleteDepartment(int departmentId)
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                var findDepartment = dbContext.tblDepartments.Find(departmentId);

                if (dbContext.tblStudyPrograms.Any(x => x.DepartmentId == departmentId))
                {
                    DeleteFault fault = new DeleteFault()
                    {
                        Result      = false,
                        Message     = "Unable to delete!",
                        Description = "Department is referenced in Study Program."
                    };

                    throw new FaultException <DeleteFault>(fault);
                }

                if (findDepartment != null)
                {
                    dbContext.tblDepartments.Remove(findDepartment);
                    dbContext.SaveChanges();
                }
            }
        }
Exemple #3
0
        public void DeleteProfessor(int professorId)
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                var findProfessor = dbContext.tblProfessors.Find(professorId);

                if (dbContext.tblCourses.Any(x => x.ProfessorId == professorId))
                {
                    DeleteFault fault = new DeleteFault()
                    {
                        Result      = false,
                        Message     = "Unable to delete!",
                        Description = "Professor is referenced in Course."
                    };

                    throw new FaultException <DeleteFault>(fault);
                }

                if (findProfessor != null)
                {
                    dbContext.tblProfessors.Remove(findProfessor);
                    dbContext.SaveChanges();
                }
            }
        }
Exemple #4
0
        public void DeleteStudyProgram(int studyProgramId)
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                var findStudyProgram = dbContext.tblStudyPrograms.Find(studyProgramId);

                if (dbContext.tblStudents.Any(x => x.StudyProgramId == studyProgramId))
                {
                    DeleteFault fault = new DeleteFault()
                    {
                        Result      = false,
                        Message     = "Unable to delete!",
                        Description = "Study Program is referenced in Student."
                    };

                    throw new FaultException <DeleteFault>(fault);
                }

                if (findStudyProgram != null)
                {
                    dbContext.tblStudyPrograms.Remove(findStudyProgram);
                    dbContext.SaveChanges();
                }
            }
        }