Esempio n. 1
0
        public void AddInstructor(POCO.Instructor ins, ref List<string> errors)
        {
            var db_instructor = new instructor();
            var db_staff = new staff();

            try
            {
                db_instructor.first_name = ins.FirstName;
                db_instructor.last_name = ins.LastName;
                db_instructor.title = ins.Title;
                db_staff.First = ins.FirstName;
                db_staff.Last = ins.LastName;
                db_staff.email = ins.FirstName.ToLower().Substring(0, 1) + ins.LastName.ToLower() + "@ucsd.edu";
                db_staff.password = ins.Password;
                this.context.instructors.Add(db_instructor);
                this.context.staffs.Add(db_staff);
                this.context.SaveChanges();
            }
            catch (Exception e)
            {
                errors.Add("Error occured in InstructorRepository.AddInstructor: " + e);
            }
        }
Esempio n. 2
0
        public List<Schedule> GetScheduleList(string year, string quarter, ref List<string> errors)
        {
            var scheduleList = new List<Schedule>();
            List<Schedule> pocoScheduleList = new List<Schedule>();
            IEnumerable<course_schedule> db_ScheduleList;

            try
            {
                var myYear = int.Parse(year);
                db_ScheduleList = this.context.course_schedule.Include("schedule_day").Include("schedule_time").Include("instructor").Where(x => x.quarter == quarter && x.year == myYear);

                foreach (course_schedule c in db_ScheduleList)
                {
                    var day = new schedule_day();
                    var time = new schedule_time();
                    var instructor = new instructor();

                    var schedule = new Schedule
                    {
                        ScheduleId = c.schedule_id,
                        Year = c.year.ToString(),
                        Quarter = c.quarter,
                        Session = c.session,
                        Instructor = new Instructor
                        {
                            InstructorId = c.instructor.instructor_id,
                            FirstName = c.instructor.first_name,
                            LastName = c.instructor.last_name,
                        },
                        Day = new ScheduleDay
                        {
                            DayId = c.schedule_day.schedule_day_id,
                            Day = c.schedule_day.schedule_day1
                        },
                        Time = new ScheduleTime
                        {
                            TimeId = c.schedule_time.schedule_time_id,
                            Time = c.schedule_time.schedule_time1
                        },
                        Course = new Course
                        {
                            CourseId = c.course.course_id,
                            Title = c.course.course_title,
                            Description = c.course.course_description
                        }
                    };

                    scheduleList.Add(schedule);
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in ScheduleRepository.GetScheduleList: " + e);
            }

            return scheduleList;
        }
Esempio n. 3
0
        public Schedule GetScheduleById(int scheduleId, ref List<string> errors)
        {
            Schedule pocoSchedule = new Schedule();
            course_schedule db_Schedule;

            try
            {
                db_Schedule = this.context.course_schedule.Find(scheduleId);

                var day = new schedule_day();
                var time = new schedule_time();
                var instructor = new instructor();
                day = this.context.schedule_day.Find((int)db_Schedule.schedule_day_id);
                time = this.context.schedule_time.Find((int)db_Schedule.schedule_time_id);
                instructor = this.context.instructors.Find((int)db_Schedule.instructor_id);

                pocoSchedule.ScheduleId = db_Schedule.schedule_id;
                pocoSchedule.Year = db_Schedule.year.ToString();
                pocoSchedule.Quarter = db_Schedule.quarter;
                pocoSchedule.Session = db_Schedule.session;
                pocoSchedule.Instructor = new Instructor
                {
                    InstructorId = instructor.instructor_id,
                    FirstName = instructor.first_name,
                    LastName = instructor.last_name,
                };
                pocoSchedule.Day = new ScheduleDay
                {
                    DayId = day.schedule_day_id,
                    Day = day.schedule_day1
                };
                pocoSchedule.Time = new ScheduleTime
                {
                    TimeId = time.schedule_time_id,
                    Time = time.schedule_time1
                };
                pocoSchedule.Course = new Course
                {
                    CourseId = db_Schedule.course.course_id,
                    Title = db_Schedule.course.course_title,
                    Description = db_Schedule.course.course_description,
                    Level = db_Schedule.course.course_level,
                };
            }
            catch (Exception e)
            {
                errors.Add("Error occured in ScheduleRepository.GetScheduleList: " + e);
            }

            return pocoSchedule;
        }
Esempio n. 4
0
        public List<Schedule> GetInstructorSchedule(int instructorId, ref List<string> errors)
        {
            IEnumerable<course_schedule> db_List;
            List<Schedule> pocoList = new List<Schedule>();

            try
            {
                db_List = this.context.course_schedule.Include("schedule_day").Include("schedule_time").Include("instructor").Where(x => x.instructor_id == instructorId);

                foreach (course_schedule c in db_List)
                {
                    var day = new schedule_day();
                    var time = new schedule_time();
                    var instructor = new instructor();

                    var schedule = new Schedule
                    {
                        ScheduleId = c.schedule_id,
                        Year = c.year.ToString(),
                        Quarter = c.quarter,
                        Session = c.session,
                        Instructor = new Instructor
                        {
                            InstructorId = c.instructor.instructor_id,
                            FirstName = c.instructor.first_name,
                            LastName = c.instructor.last_name,
                        },
                        Day = new ScheduleDay
                        {
                            DayId = c.schedule_day.schedule_day_id,
                            Day = c.schedule_day.schedule_day1
                        },
                        Time = new ScheduleTime
                        {
                            TimeId = c.schedule_time.schedule_time_id,
                            Time = c.schedule_time.schedule_time1
                        },
                        Course = new Course
                        {
                            CourseId = c.course.course_id,
                            Title = c.course.course_title,
                            Description = c.course.course_description,
                            Level = c.course.course_level,
                        }
                    };

                    pocoList.Add(schedule);
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in ScheduleRepository.GetDays: " + e);
            }

            return pocoList;
        }
Esempio n. 5
0
        public void RemoveInstructor(int instructor_id, ref List<string> errors)
        {
            var db_instructor = new instructor();
            var db_staff = new staff();

            try
            {
                db_instructor = this.context.instructors.Find(instructor_id);
                db_staff = this.context.staffs.Find(instructor_id);
                this.context.staffs.Remove(db_staff);
                this.context.instructors.Remove(db_instructor);
                this.context.SaveChanges();
            }
            catch (Exception e)
            {
                errors.Add("Error occured in InstructorRepository.RemoveInstructor: " + e);
            }
        }
Esempio n. 6
0
        ////good method for validation when adding new course
        public bool IsNotDuplicateInstructor(POCO.Instructor ins, ref List<string> errors)
        {
            var db_instructor = new instructor();

            try
            {
                var isDuplicate = this.context.instructors.Where(
                    x => x.first_name == ins.FirstName &&
                    x.last_name == ins.LastName &&
                    x.title == ins.Title).Count() > 0;

                if (isDuplicate)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in in InstructorRepository.IsDuplicateInstructor: " + e);
            }

            return false;
        }