示例#1
0
        public CapeReview FindCapeReviewByScheduleId(int schedule_id, ref List<string> errors)
        {
            CapeReview pocoCR = new CapeReview();
            course_schedule db_schedule = new course_schedule();
            cape_reviews db_cr = new cape_reviews();

            try
            {
                db_schedule = this.context.course_schedule.Find(schedule_id);
                db_cr = this.context.cape_reviews.Where(x => x.course_id == db_schedule.course_id &&
                                x.instructor_id == (int)db_schedule.instructor_id).First();
                pocoCR.CapeId = db_cr.cape_id;
                pocoCR.CourseId = (int)db_cr.course_id;
                pocoCR.CourseRating = (int)db_cr.course_rating;
                pocoCR.InstructorId = (int)db_cr.instructor_id;
                pocoCR.InstructorRating = (int)db_cr.instructor_rating;
                pocoCR.Summary = db_cr.summary;
            }
            catch (Exception e)
            {
                errors.Add("Error occured in CapeReviewRepository.FindCapeReviewById: " + e);
            }

            return pocoCR;
        }
示例#2
0
        public void AddCourseToSchedule(Schedule schedule, ref List<string> errors)
        {
            course_schedule db_Schedule = new course_schedule();

            try
            {
                db_Schedule.course_id = schedule.Course.CourseId;
                db_Schedule.instructor_id = schedule.Instructor.InstructorId;
                db_Schedule.schedule_day_id = schedule.Day.DayId;
                db_Schedule.schedule_time_id = schedule.Time.TimeId;
                db_Schedule.year = int.Parse(schedule.Year);
                db_Schedule.quarter = schedule.Quarter;
                db_Schedule.session = schedule.Session;
                this.context.course_schedule.Add(db_Schedule);
                this.context.SaveChanges();
            }
            catch (Exception e)
            {
                errors.Add("Error occured in ScheduleRepository.AddCourseToSchedule: " + e);
            }
        }
示例#3
0
        public void GetStudentHistory(string studentId, ref List<string> errors)
        {
            IEnumerable<int> db_ScheduleIdList;
            List<course_schedule> db_CourseScheduleList = new List<course_schedule>();

            try
            {
                db_ScheduleIdList = this.context.enrollments.Where(x => x.student_id == studentId).Select(y => y.schedule_id);
                foreach (int scheduleId in db_ScheduleIdList)
                {
                    course_schedule tmpSchedule = new course_schedule();
                    tmpSchedule.schedule_id = scheduleId;
                    tmpSchedule = this.context.course_schedule.Find(tmpSchedule);
                    db_CourseScheduleList.Add(tmpSchedule);
                }
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e);
            }
        }
示例#4
0
        public Student FindStudentById(int student_id, ref List<string> errors)
        {
            student db_student;
            Student pocoStudent = new Student();

            try
            {
                db_student = this.context.students.Find(student_id);
                pocoStudent.StudentId = db_student.student_id;
                pocoStudent.FirstName = db_student.first_name;
                pocoStudent.LastName = db_student.last_name;
                pocoStudent.Password = db_student.password;
                pocoStudent.Email = db_student.email;
                pocoStudent.Enrolled = new List<Schedule>();
                foreach (enrollment enrolledCourse in db_student.enrollments)
                {
                    var pocoSchedule = new Schedule();
                    var db_Schedule = new course_schedule();

                    db_Schedule.schedule_id = enrolledCourse.schedule_id;
                    db_Schedule = this.context.course_schedule.Find(db_Schedule);

                    pocoSchedule.ScheduleId = db_Schedule.schedule_id;
                    pocoSchedule.Quarter = db_Schedule.quarter;
                    pocoSchedule.Year = db_Schedule.year.ToString();
                    pocoSchedule.Session = db_Schedule.session;

                    pocoStudent.Enrolled.Add(pocoSchedule);
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in StudentRepository.FindStudentById: " + e);
            }

            return pocoStudent;
        }
示例#5
0
        public void UpdateCourseFromSchedule(Schedule schedule, ref List<string> errors)
        {
            course_schedule db_Schedule = new course_schedule();

            try
            {
                db_Schedule = this.context.course_schedule.Find(schedule.ScheduleId);
                db_Schedule.instructor_id = schedule.Instructor.InstructorId;
                db_Schedule.schedule_day_id = schedule.Day.DayId;
                db_Schedule.schedule_time_id = schedule.Time.TimeId;
                db_Schedule.session = schedule.Session;
                this.context.SaveChanges();
            }
            catch (Exception e)
            {
                errors.Add("Error occured in ScheduleRepository.AddCourseToSchedule: " + e);
            }
        }
示例#6
0
        public void RemoveCourseFromSchedule(int scheduleId, ref List<string> errors)
        {
            var db_Schedule = new course_schedule();
            IEnumerable<enrollment> deleteEnrollments;

            try
            {
                db_Schedule = this.context.course_schedule.Find(scheduleId);
                db_Schedule = this.context.course_schedule.Remove(db_Schedule);
                deleteEnrollments = this.context.enrollments.Where(x => x.schedule_id == scheduleId);
                foreach (enrollment deleteMe in deleteEnrollments)
                {
                    this.context.enrollments.Remove(deleteMe);
                }

                this.context.SaveChanges();
            }
            catch (Exception e)
            {
                errors.Add("Error occured in ScheduleRepository.RemoveCourseFromSchedule: " + e);
            }
        }