Ejemplo 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);
            }
        }
Ejemplo n.º 2
0
        public Instructor FindInstructorById(int instId, ref List<string> errors)
        {
            POCO.Instructor pocoInstructor = new POCO.Instructor();
            instructor db_instructor;
            var db_staff = new staff();

            try
            {
                db_instructor = this.context.instructors.Find(instId);
                if (db_instructor != null)
                {
                    db_staff = this.context.staffs.Find(instId);

                    if (db_instructor != null)
                    {
                        pocoInstructor.InstructorId = db_instructor.instructor_id;
                        pocoInstructor.FirstName = db_instructor.first_name;
                        pocoInstructor.LastName = db_instructor.last_name;
                        pocoInstructor.Title = db_instructor.title;
                        pocoInstructor.Password = db_staff.password;
                    }
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in InstructorRepository.FindInstructorById: " + e);
            }

            return pocoInstructor;
        }
Ejemplo n.º 3
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);
            }
        }