Ejemplo n.º 1
0
        public string AddEnrollment(Enrollment enrollment)
        {
            var errors = new List<string>();
            var repository = new EnrollmentRepository(this.entities);
            var service = new EnrollmentService(repository);
            service.AddEnrollment(enrollment.StudentId, enrollment.ScheduleId, ref errors);

            if (errors.Count == 0)
            {
                return "ok";
            }

            return "error";
        }
Ejemplo n.º 2
0
        public List<POCO.Enrollment> GetAllStudentEnrolledSchedules(string studentId, ref List<string> errors)
        {
            IEnumerable<enrollment> studentEnrollments;
            List<POCO.Enrollment> pocoEnrollmentList = new List<POCO.Enrollment>();

            try
            {
                studentEnrollments = this.context.enrollments.Include("course_schedule").Where(x => x.student_id == studentId);
                foreach (enrollment enrolled in studentEnrollments)
                {
                    var poco = new POCO.Enrollment();
                    poco.EnrolledSchedule = new Schedule();
                    poco.EnrolledSchedule.Course = new Course();
                    poco.EnrolledSchedule.Instructor = new Instructor();
                    poco.EnrolledSchedule.Day = new ScheduleDay();
                    poco.EnrolledSchedule.Time = new ScheduleTime();

                    poco.ScheduleId = enrolled.schedule_id;
                    poco.StudentId = enrolled.student_id;
                    poco.Grade = enrolled.grade;

                    poco.EnrolledSchedule.ScheduleId = enrolled.course_schedule.schedule_id;
                    poco.EnrolledSchedule.Year = enrolled.course_schedule.year.ToString();
                    poco.EnrolledSchedule.Quarter = enrolled.course_schedule.quarter;
                    poco.EnrolledSchedule.Session = enrolled.course_schedule.session;

                    poco.EnrolledSchedule.Course.CourseId = enrolled.course_schedule.course.course_id;
                    poco.EnrolledSchedule.Course.Title = enrolled.course_schedule.course.course_title;

                    poco.EnrolledSchedule.Instructor.InstructorId = enrolled.course_schedule.instructor.instructor_id;
                    poco.EnrolledSchedule.Instructor.FirstName = enrolled.course_schedule.instructor.first_name;
                    poco.EnrolledSchedule.Instructor.LastName = enrolled.course_schedule.instructor.last_name;

                    poco.EnrolledSchedule.Day.DayId = enrolled.course_schedule.schedule_day.schedule_day_id;
                    poco.EnrolledSchedule.Day.Day = enrolled.course_schedule.schedule_day.schedule_day1;

                    poco.EnrolledSchedule.Time.TimeId = enrolled.course_schedule.schedule_time.schedule_time_id;
                    poco.EnrolledSchedule.Time.Time = enrolled.course_schedule.schedule_time.schedule_time1;

                    pocoEnrollmentList.Add(poco);
                }
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e);
            }

            return pocoEnrollmentList;
        }
Ejemplo n.º 3
0
        public void AddEnrollmentTest()
        {
            //// Arranage
            var errors = new List<string>();

            Mock<IEnrollmentRepository> mockRepository = new Mock<IEnrollmentRepository>();
            EnrollmentService iserv = new EnrollmentService(mockRepository.Object);

            Enrollment s = new Enrollment { StudentId = "99", ScheduleId = 1000, Grade = "A+", GradeValue = 3.0f };

            mockRepository.Setup(x => x.AddEnrollment("99", 1000, ref errors));
            mockRepository.Setup(x => x.IsNotDuplicateEnrollment("99", 1000, ref errors)).Returns(true);

            //// Act
            iserv.AddEnrollment("99", 1000, ref errors);

            //// Assert
            mockRepository.Verify(x => x.AddEnrollment("99", 1000, ref errors), Times.Once());
        }
Ejemplo n.º 4
0
        public string UpdateEnrollment(Enrollment er)
        {
            var errors = new List<string>();
            var repository = new EnrollmentRepository(this.entities);
            var service = new EnrollmentService(repository);

            service.UpdateEnrollment(er, ref errors);

            if (errors.Count == 0)
            {
                return "ok";
            }

            return "error";
        }
Ejemplo n.º 5
0
        public List<Enrollment> GetEnrollments(string studentId, ref List<string> errors)
        {
            IEnumerable<enrollment> db_EnrollmentList;
            List<Enrollment> poco_EnrollmentList = new List<Enrollment>();
            try
            {
                db_EnrollmentList = this.context.enrollments.Where(x => x.student_id == studentId);
                foreach (enrollment enrolledSchedule in db_EnrollmentList)
                {
                    Enrollment poco_Enrollment = new Enrollment();
                    poco_Enrollment.Grade = enrolledSchedule.grade;
                    poco_Enrollment.ScheduleId = enrolledSchedule.schedule_id;
                    poco_Enrollment.StudentId = studentId;
                    poco_EnrollmentList.Add(poco_Enrollment);
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in StudentRepository.GetEnrollments: " + e);
            }

            return poco_EnrollmentList;
        }
Ejemplo n.º 6
0
        public Enrollment GetEnrollmentDetail(string studentId, int scheduleId, ref List<string> errors)
        {
            var db_Enrollment = new enrollment();
            var poco = new Enrollment();

            try
            {
                db_Enrollment = this.context.enrollments.Where(x => x.schedule_id == scheduleId && x.student_id == studentId).First();
                poco.StudentId = db_Enrollment.student_id;
                poco.ScheduleId = db_Enrollment.schedule_id;
                poco.Grade = db_Enrollment.grade;
            }
            catch (Exception e)
            {
                errors.Add("Error occured in EnrollmentRepository.AddEnrollment: " + e);
            }

            return poco;
        }
Ejemplo n.º 7
0
        public void UpdateEnrollment(Enrollment er, ref List<string> errors)
        {
            var db_Enrollment = new enrollment();

            try
            {
                db_Enrollment = this.context.enrollments.Where(x => x.schedule_id == er.ScheduleId && x.student_id == er.StudentId).First();
                db_Enrollment.grade = er.Grade;
                this.context.SaveChanges();
            }
            catch (Exception e)
            {
                errors.Add("Error occured in EnrollmentRepository.AddEnrollment: " + e);
            }
        }
        public List<Enrollment> GetEnrollments(string studentId)
        {
            var conn = new SqlConnection(ConnectionString);
            var enrollmentList = new List<Enrollment>();

            try
            {
                var adapter = new SqlDataAdapter(GetEnrollmentListProcedure, conn)
                {
                    SelectCommand =
                    {
                        CommandType = CommandType.StoredProcedure
                    }
                };
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@student_id", SqlDbType.VarChar, 20));

                adapter.SelectCommand.Parameters["@student_id"].Value = studentId;

                var dataSet = new DataSet();
                adapter.Fill(dataSet);

                if (dataSet.Tables[0].Rows.Count == 0)
                {
                    return null;
                }

                for (var i = 0; i < dataSet.Tables[0].Rows.Count; i++)
                {
                    var enrollment = new Enrollment
                    {
                        StudentId = dataSet.Tables[0].Rows[i]["student_id"].ToString(),
                        ScheduleId =
                            (int)
                            Convert.ToInt32(dataSet.Tables[0].Rows[i]["schedule_id"].ToString()),
                        Grade = dataSet.Tables[0].Rows[i]["grade"].ToString(),
                        GradeChange =
                            (bool)
                            Convert.ToBoolean(dataSet.Tables[0].Rows[i]["grade_change"].ToString()),
                        GradingOption = dataSet.Tables[0].Rows[i]["grading_opt"].ToString(),
                     };
                     enrollmentList.Add(enrollment);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                conn.Dispose();
            }

            return enrollmentList;
        }
Ejemplo n.º 9
0
 public void UpdateEnrollment(Enrollment er, ref List<string> errors)
 {
     this.repository.UpdateEnrollment(er, ref errors);
 }