Beispiel #1
0
        public IEnumerable <Course> GetAllCourses()
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                var           dbCourses = dbContext.CourseView.ToList();
                List <Course> courses   = new List <Course>(dbCourses.Count);

                foreach (var dbCourse in dbCourses)
                {
                    Course course = new Course()
                    {
                        CourseId         = dbCourse.CourseId,
                        Name             = dbCourse.Name,
                        StudyProgramId   = dbCourse.StudyProgramId,
                        StudyProgramName = dbCourse.StudyProgramName,
                        ProfessorId      = dbCourse.ProfessorId,
                        ProfessorName    = dbCourse.ProfessorName,
                        Assistant        = dbCourse.Assistant,
                        ETCS             = dbCourse.ETCS
                    };

                    courses.Add(course);
                }

                return(courses);
            }
        }
        public IHttpActionResult UpdateStudentDetail(Student student)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                Student stud = new Student();

                using (var database = new StudentDbEntities())
                {
                    stud = database.Students.Find(student.StudentId);
                    if (stud != null)
                    {
                        stud.Name           = student.Name;
                        stud.MobileNumber   = student.MobileNumber;
                        stud.EmailId        = student.EmailId;
                        stud.CourseEnrolled = student.CourseEnrolled;
                        stud.FeesStatus     = student.FeesStatus;

                        var update = database.spUpdate(student.StudentId, student.Name, student.MobileNumber, student.EmailId, student.CourseEnrolled, student.FeesStatus);
                        database.SaveChanges();
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(Ok(student));
        }
 public UserViewModelsController()
 {
     this.db             = new StudentDbEntities();
     repositoryFactory   = new ServiceFactory(db);
     this.userRepository = repositoryFactory.GetUserRepository();
     this.subjectRepo    = repositoryFactory.GetSubjectRepository();
 }
Beispiel #4
0
        public Course AddCourse(Course newCourse)
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                var addCourse = new tblCourses()
                {
                    Name           = newCourse.Name,
                    StudyProgramId = newCourse.StudyProgramId,
                    ProfessorId    = newCourse.ProfessorId,
                    Assistant      = newCourse.Assistant,
                    ETCS           = newCourse.ETCS
                };

                dbContext.tblCourses.Add(addCourse);
                dbContext.SaveChanges();

                var newCourseId = dbContext.CourseView.SingleOrDefault(x => x.CourseId == addCourse.CourseId);

                return(new Course()
                {
                    CourseId = newCourseId.CourseId,
                    Name = newCourseId.Name,
                    StudyProgramId = newCourseId.StudyProgramId,
                    StudyProgramName = newCourseId.StudyProgramName,
                    ProfessorId = newCourseId.ProfessorId,
                    ProfessorName = newCourseId.ProfessorName,
                    Assistant = newCourseId.Assistant,
                    ETCS = newCourseId.ETCS
                });
            }
        }
Beispiel #5
0
        private void ViewUpdate()
        {
            StudentDbEntities context = new StudentDbEntities();
            var qry = context.Students.ToList();

            dataGridView1.DataSource = qry;
        }
Beispiel #6
0
        public ExamPeriod AddExamPeriod(ExamPeriod newExamPeriod)
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                var addExamPeriod = new tblExamPeriods()
                {
                    Name        = newExamPeriod.Name,
                    StartDate   = newExamPeriod.StartDate,
                    EndDate     = newExamPeriod.EndDate,
                    SchoolYear  = newExamPeriod.SchoolYear,
                    IsActive    = newExamPeriod.IsActive,
                    IsApsolvent = newExamPeriod.IsApsolvent
                };

                dbContext.tblExamPeriods.Add(addExamPeriod);
                dbContext.SaveChanges();

                var newExamPeriodId = dbContext.tblExamPeriods.SingleOrDefault(x => x.ExamPeriodId == addExamPeriod.ExamPeriodId);

                return(new ExamPeriod()
                {
                    ExamPeriodId = newExamPeriodId.ExamPeriodId,
                    Name = newExamPeriodId.Name,
                    StartDate = newExamPeriodId.StartDate,
                    EndDate = newExamPeriodId.EndDate,
                    SchoolYear = newExamPeriodId.SchoolYear,
                    IsActive = newExamPeriodId.IsActive,
                    IsApsolvent = newExamPeriodId.IsApsolvent
                });
            }
        }
Beispiel #7
0
 public HomeController()
 {
     this.ctx = new StudentDbEntities();
     this.repositoryFactory = new ServiceFactory(ctx);
     this.userRepository    = repositoryFactory.GetUserRepository();
     this.reportsRepository = repositoryFactory.GetReportsRepository();
 }
Beispiel #8
0
        public IEnumerable <ExamPeriod> GetAllExamPeriods()
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                var dbExamPeriods             = dbContext.tblExamPeriods.ToList();
                List <ExamPeriod> examPeriods = new List <ExamPeriod>(dbExamPeriods.Count);

                foreach (var dbExamPeriod in dbExamPeriods)
                {
                    ExamPeriod examPeriod = new ExamPeriod()
                    {
                        ExamPeriodId = dbExamPeriod.ExamPeriodId,
                        Name         = dbExamPeriod.Name,
                        StartDate    = dbExamPeriod.StartDate,
                        EndDate      = dbExamPeriod.EndDate,
                        SchoolYear   = dbExamPeriod.SchoolYear,
                        IsActive     = dbExamPeriod.IsActive,
                        IsApsolvent  = dbExamPeriod.IsApsolvent
                    };

                    examPeriods.Add(examPeriod);
                }

                return(examPeriods);
            }
        }
Beispiel #9
0
        public IEnumerable <Student> GetAllStudents()
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                var            dbStudents = dbContext.StudentView.ToList();
                List <Student> students   = new List <Student>(dbStudents.Count);

                foreach (var dbStudent in dbStudents)
                {
                    Student student = new Student();
                    student.StudentId        = dbStudent.StudentId;
                    student.DepartmentId     = dbStudent.DepartmentId;
                    student.StudyProgramId   = dbStudent.StudyProgramId;
                    student.NameAndSurname   = dbStudent.NameAndSurname;
                    student.Address          = dbStudent.Address;
                    student.Balance          = dbStudent.Balance;
                    student.BirthDate        = dbStudent.BirthDate;
                    student.BirthPlace       = dbStudent.BirthPlace;
                    student.StudyProgramName = dbStudent.StudyProgramName;
                    student.DepartmentName   = dbStudent.DepartmantName;
                    student.Username         = dbStudent.Username;
                    student.Password         = dbStudent.Password;
                    student.Phone            = dbStudent.Phone;
                    student.StudyYear        = dbStudent.StudyYear;

                    students.Add(student);
                }

                return(students);
            }
        }
Beispiel #10
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();
                }
            }
        }
Beispiel #11
0
        public IEnumerable <Exam> GetAllExams()
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                var         dbExams = dbContext.ExamView.ToList();
                List <Exam> exams   = new List <Exam>(dbExams.Count);

                foreach (var dbExam in dbExams)
                {
                    Exam exam = new Exam()
                    {
                        ExamId         = dbExam.ExamId,
                        ExamPeriodId   = dbExam.ExamPeriodId,
                        ExamPeriodName = dbExam.ExamPeriodName,
                        CourseId       = dbExam.CourseId,
                        CourseName     = dbExam.CourseName,
                        DateAndTime    = dbExam.DateAndTime,
                        Place          = dbExam.Place,
                        Price          = dbExam.Price,
                        IsPassed       = dbExam.IsPassed
                    };

                    exams.Add(exam);
                }

                return(exams);
            }
        }
Beispiel #12
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();
                }
            }
        }
Beispiel #13
0
        public IEnumerable <Professor> GetAllProfessors()
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                var dbProfessors            = dbContext.tblProfessors.ToList();
                List <Professor> professors = new List <Professor>(dbProfessors.Count);

                foreach (var dbProfessor in dbProfessors)
                {
                    Professor prof = new Professor()
                    {
                        ProfessorId    = dbProfessor.ProfessorId,
                        NameAndSurname = dbProfessor.NameAndSurname,
                        Address        = dbProfessor.Address,
                        BirthDate      = dbProfessor.BirthDate,
                        BirthPlace     = dbProfessor.BirthPlace,
                        Education      = dbProfessor.Education,
                        Phone          = dbProfessor.Phone,
                        IsAdmin        = dbProfessor.IsAdmin,
                        Username       = dbProfessor.Username,
                        Password       = dbProfessor.Password
                    };

                    professors.Add(prof);
                }

                return(professors);
            }
        }
Beispiel #14
0
        public Department AddDepartment(Department newDepartment)
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                var addDepartment = new tblDepartments()
                {
                    Name           = newDepartment.Name,
                    FoundationYear = newDepartment.FoundationYear,
                    DepartmentHead = newDepartment.DepartmentHead,
                    Website        = newDepartment.Website
                };

                dbContext.tblDepartments.Add(addDepartment);
                dbContext.SaveChanges();

                var newDepartmentId = dbContext.tblDepartments.SingleOrDefault(x => x.DepartmentId == addDepartment.DepartmentId);

                return(new Department()
                {
                    DepartmentId = newDepartmentId.DepartmentId,
                    Name = newDepartmentId.Name,
                    FoundationYear = newDepartmentId.FoundationYear,
                    DepartmentHead = newDepartmentId.DepartmentHead,
                    Website = newDepartmentId.Website
                });
            }
        }
Beispiel #15
0
        public Exam AddExam(Exam newExam)
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                var addExam = new tblExams()
                {
                    ExamPeriodId = newExam.ExamPeriodId,
                    CourseId     = newExam.CourseId,
                    DateAndTime  = newExam.DateAndTime,
                    Place        = newExam.Place,
                    Price        = newExam.Price,
                    IsPassed     = newExam.IsPassed
                };

                dbContext.tblExams.Add(addExam);
                dbContext.SaveChanges();

                var newExamId = dbContext.ExamView.SingleOrDefault(x => x.ExamId == addExam.ExamId);

                return(new Exam()
                {
                    ExamId = newExamId.ExamId,
                    ExamPeriodId = newExamId.ExamPeriodId,
                    ExamPeriodName = newExamId.ExamPeriodName,
                    CourseId = newExamId.CourseId,
                    CourseName = newExamId.CourseName,
                    DateAndTime = newExamId.DateAndTime,
                    Place = newExamId.Place,
                    Price = newExamId.Price,
                    IsPassed = newExamId.IsPassed
                });
            }
        }
Beispiel #16
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();
                }
            }
        }
Beispiel #17
0
        public IEnumerable <ExamPeriod> GetActiveExamPeriods()
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                List <ExamPeriod> examPeriods = new List <ExamPeriod>();

                var activeExamPeriods = dbContext.tblExamPeriods.Where(x => x.IsActive == true);
                var date = DateTime.Now.ToLocalTime();

                foreach (var activeExamPeriod in activeExamPeriods)
                {
                    ExamPeriod ep = new ExamPeriod()
                    {
                        ExamPeriodId = activeExamPeriod.ExamPeriodId,
                        Name         = activeExamPeriod.Name,
                        StartDate    = activeExamPeriod.StartDate,
                        EndDate      = activeExamPeriod.EndDate
                    };

                    examPeriods.Add(ep);
                }

                return(examPeriods);
            }
        }
Beispiel #18
0
        public StudyProgram AddStudyProgram(StudyProgram newStudyProgram)
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                var addStudyProgram = new tblStudyPrograms()
                {
                    Name               = newStudyProgram.Name,
                    DepartmentId       = newStudyProgram.DepartmentId,
                    BudgetPlaces       = newStudyProgram.BudgetPlaces,
                    SelffinancedPlaces = newStudyProgram.SelffinancedPlaces,
                    Tuition            = newStudyProgram.Tuition
                };

                dbContext.tblStudyPrograms.Add(addStudyProgram);
                dbContext.SaveChanges();

                var newSPId = dbContext.StudyProgramView.SingleOrDefault(x => x.StudyProgramId == addStudyProgram.StudyProgramId);

                return(new StudyProgram()
                {
                    StudyProgramId = newSPId.StudyProgramId,
                    Name = newSPId.Name,
                    DepartmentId = newSPId.DepartmentId,
                    DepartmentName = newSPId.DepartmentName,
                    BudgetPlaces = newSPId.BudgetPlaces,
                    SelffinancedPlaces = newSPId.SelffinancedPlaces,
                    Tuition = newSPId.Tuition
                });
            }
        }
Beispiel #19
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();
                }
            }
        }
Beispiel #20
0
        public bool SetExamResults(List <ExamResult> examResults)
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                try
                {
                    foreach (var examResult in examResults)
                    {
                        var examResultForInsert = new tblExamResults()
                        {
                            ExamRegistrationId = examResult.ExamRegistrationId,
                            FirstTest          = examResult.FirstTest,
                            SecondTest         = examResult.SecondTest,
                            TermPaper          = examResult.TermPaper,
                            WritenExam         = examResult.WritenExam,
                            Total      = examResult.Total,
                            Evaluation = examResult.Evaluation
                        };

                        dbContext.tblExamResults.Add(examResultForInsert);
                    }

                    dbContext.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    e.StackTrace.ToString();
                    return(false);
                }
            }
        }
Beispiel #21
0
 public void DeleteCourse(int courseId)
 {
     using (StudentDbEntities dbContext = new StudentDbEntities())
     {
         var findCourse = dbContext.tblCourses.Find(courseId);
         if (findCourse != null)
         {
             dbContext.tblCourses.Remove(findCourse);
             dbContext.SaveChanges();
         }
     }
 }
Beispiel #22
0
 public void DeleteStudent(int studentId)
 {
     using (StudentDbEntities dbContext = new StudentDbEntities())
     {
         var findStudent = dbContext.tblStudents.Find(studentId);
         if (findStudent != null)
         {
             dbContext.tblStudents.Remove(findStudent);
             dbContext.SaveChanges();
         }
     }
 }
Beispiel #23
0
 public void DeleteExam(int examId)
 {
     using (StudentDbEntities dbContext = new StudentDbEntities())
     {
         var findExam = dbContext.tblExams.Find(examId);
         if (findExam != null)
         {
             dbContext.tblExams.Remove(findExam);
             dbContext.SaveChanges();
         }
     }
 }
Beispiel #24
0
        private void button2_Click(object sender, EventArgs e)
        {
            int id = Int16.Parse(tbStdID.Text);
            StudentDbEntities context = new StudentDbEntities();
            Student           std     = context.Students.Where(x => x.StudentId == id).First();

            context.Students.Remove(std);
            context.SaveChanges();
            context.SaveChanges();
            MessageBox.Show("Successfully Deleted");
            ViewUpdate();
            Reset();
        }
Beispiel #25
0
        private void btnFind_Click(object sender, EventArgs e)
        {
            int id = Int16.Parse(tbStdID.Text);
            StudentDbEntities context = new StudentDbEntities();
            Student           std     = context.Students.Where(x => x.StudentId == id).First();

            tbStdID.Text      = std.StudentId.ToString();
            tbStdName.Text    = std.Name;
            tbStdAddress.Text = std.Address;
            tbStdAge.Text     = std.Age.ToString();
            tbStdGender.Text  = std.Gender;
            tbStdPhone.Text   = std.Phone;
            ViewUpdate();
        }
Beispiel #26
0
        public void EditDepartment(Department editedDepartment)
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                var dbDepartment = dbContext.tblDepartments.Find(editedDepartment.DepartmentId);

                dbDepartment.Name           = editedDepartment.Name;
                dbDepartment.DepartmentHead = editedDepartment.DepartmentHead;
                dbDepartment.FoundationYear = editedDepartment.FoundationYear;
                dbDepartment.Website        = editedDepartment.Website;

                dbContext.SaveChanges();
            }
        }
Beispiel #27
0
        public void EditStudyProgram(StudyProgram editedStudyProgram)
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                var dbStudyProgram = dbContext.tblStudyPrograms.SingleOrDefault(x => x.StudyProgramId == editedStudyProgram.StudyProgramId);

                dbStudyProgram.Name               = editedStudyProgram.Name;
                dbStudyProgram.DepartmentId       = editedStudyProgram.DepartmentId;
                dbStudyProgram.BudgetPlaces       = editedStudyProgram.BudgetPlaces;
                dbStudyProgram.SelffinancedPlaces = editedStudyProgram.SelffinancedPlaces;
                dbStudyProgram.Tuition            = editedStudyProgram.Tuition;

                dbContext.SaveChanges();
            }
        }
Beispiel #28
0
        private void button1_Click(object sender, EventArgs e)
        {
            int id = Int16.Parse(tbStdID.Text);
            StudentDbEntities context = new StudentDbEntities();
            Student           std     = context.Students.Where(x => x.StudentId == id).First();

            std.Name    = tbStdName.Text;
            std.Address = tbStdAddress.Text;
            std.Age     = Int16.Parse(tbStdAge.Text);
            std.Gender  = tbStdGender.Text;
            std.Phone   = tbStdPhone.Text;
            context.SaveChanges();
            MessageBox.Show("Update is successful");
            ViewUpdate();
        }
Beispiel #29
0
        public void EditCourse(Course editedCourse)
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                var dbCourse = dbContext.tblCourses.SingleOrDefault(x => x.CourseId == editedCourse.CourseId);

                dbCourse.Name           = editedCourse.Name;
                dbCourse.StudyProgramId = editedCourse.StudyProgramId;
                dbCourse.ProfessorId    = editedCourse.ProfessorId;
                dbCourse.Assistant      = editedCourse.Assistant;
                dbCourse.ETCS           = editedCourse.ETCS;

                dbContext.SaveChanges();
            }
        }
        public IHttpActionResult DeleteStudentDetail(int studentId)
        {
            using (var database = new StudentDbEntities())
            {
                Student stud = new Student();

                stud = student.Students.Find(studentId);
                if (stud == null)
                {
                    return(NotFound());
                }
                var delete = database.spDelete(studentId);
                database.SaveChanges();
            }
            return(Ok(student));
        }