Пример #1
0
        //Method to Enroll a student is a course
        public bool EnrollInCourse(int studentId, int courseId)
        {
            bool isEnrolled = false;

            try
            {
                isEnrolled = new EnrollmentRepo().Insert(new Enrollment
                {
                    StudentID = studentId,
                    CourseID  = courseId
                });
            }
            catch (Exception ex)
            {
                throw new PrometheusException(ex.Message);
            }
            return(isEnrolled);
        }
Пример #2
0
        /*public List<Student> SearchStudents(int CourseID)
         * {
         *  StudentRepo studentrepo = new StudentRepo();
         *  List<Student> StudentList = studentrepo.GetStudents();
         *
         *  //as we need to create list, we need collection that will only be generated from object
         *  var result = studentList.Where(
         *      item => item.HomeWorkID == CourseID
         *  ).Join(
         *          homeworkList,
         *          assignment => assignment.HomeWorkID,
         *          homework => homework.HomeworkID,
         *          (assignment, homework) => new AssignedHomework
         *          {
         *              AssignmentID = assignment.AssignmentID,
         *              TeacherID = assignment.TeacherID,
         *              CourseID = assignment.CourseID,
         *              HomeworkID = homework.HomeworkID,
         *              Description = homework.Description,
         *              LongDescription = homework.LongDescription
         *          }
         *      ).ToList();
         *  if (result.Any())
         *  {
         *      return result;
         *  }
         *  else
         *  {
         *      throw new Exception("No Homeworks Found!");*/


        //Method for getting List of Student For a given course Id.
        public List <Student> GetStudentsByCourseId(int id)
        {
            try
            {
                EnrollmentRepo    enrollmentRepo = new EnrollmentRepo();
                List <Enrollment> enrollments    = enrollmentRepo.GetEnrollments().Where(item => item.CourseID == id).ToList();
                StudentRepo       studentRepo    = new StudentRepo();
                List <Student>    students       = studentRepo.GetStudents();

                var result = enrollments.Join(
                    students,
                    enrollment => enrollment.StudentID,
                    student => student.StudentID,

                    (enrollment, student) => new Student
                {
                    StudentID = enrollment.StudentID,
                    FName     = student.FName,
                    LName     = student.LName,
                    Address   = student.Address,
                    DOB       = student.DOB,
                    City      = student.City,
                    UserID    = student.UserID,
                    MobileNo  = student.MobileNo
                }
                    ).ToList();
                if (result.Any())
                {
                    return(result);
                }
                else
                {
                    throw new PrometheusException("No Enrolled Student Found!");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #3
0
        //Get List of Courses in which student is Enrolled
        public List <EnrolledCourse> GetCoursesByStudentID(int id)
        {
            try
            {
                EnrollmentRepo    enrollmentRepo = new EnrollmentRepo();
                List <Enrollment> enrollments    = enrollmentRepo.GetEnrollments();
                CourseRepo        courseRepo     = new CourseRepo();
                List <Course>     courses        = courseRepo.GetCourses();

                var result = enrollments.Where(item => item.StudentID == id).Join(
                    courses,
                    enrollment => enrollment.CourseID,
                    course => course.CourseID,
                    (enrollment, course) => new EnrolledCourse
                {
                    EnrollmentID = enrollment.EnrollmentID,
                    CourseID     = enrollment.CourseID,
                    Name         = course.Name,
                    StartDate    = course.StartDate,
                    EndDate      = course.EndDate
                }
                    ).ToList();
                if (result.Any())
                {
                    return(result);
                }
                else
                {
                    throw new PrometheusException("No Enrollments Found!");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }