コード例 #1
0
        public List<Course> GetCourseList(ref List<string> errors)
        {
            var conn = new SqlConnection(ConnectionString);
            var courseList = new List<Course>();

            try
            {
                var adapter = new SqlDataAdapter(GetCourseListProcedure, conn)
                                  {
                                      SelectCommand =
                                          {
                                              CommandType = CommandType.StoredProcedure
                                          }
                                  };

                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 course = new Course
                                     {
                                         CourseId = dataSet.Tables[0].Rows[i]["course_id"].ToString(),
                                         Title = dataSet.Tables[0].Rows[i]["course_title"].ToString(),
                                         CourseLevel =
                                             (CourseLevel)
                                             Enum.Parse(
                                                 typeof(CourseLevel),
                                                 dataSet.Tables[0].Rows[i]["course_level"].ToString()),
                                         Description = dataSet.Tables[0].Rows[i]["course_description"].ToString()
                                     };
                    courseList.Add(course);
                }
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e);
            }
            finally
            {
                conn.Dispose();
            }

            return courseList;
        }
コード例 #2
0
ファイル: CourseServiceTest.cs プロジェクト: fastily/cse136
        public void AddCourseTest()
        {
            //// Arranage
            var errors = new List<string>();

            Mock<ICourseRepository> mockRepository = new Mock<ICourseRepository>();
            CourseService iserv = new CourseService(mockRepository.Object);

            Course s = new Course { CourseId = 99, Title = "T", Description = "Test" };

            mockRepository.Setup(x => x.AddCourse(s, ref errors));
            mockRepository.Setup(x => x.IsNotDuplicateCourse(s, ref errors)).Returns(true);

            //// Act
            iserv.InsertCourse(s, ref errors);

            //// Assert
            mockRepository.Verify(x => x.AddCourse(s, ref errors), Times.Once());
        }
コード例 #3
0
ファイル: CourseRepository.cs プロジェクト: fastily/cse136
        public Course FindCourseById(int courseId, ref List<string> errors)
        {
            POCO.Course pocoCourse = new POCO.Course();
            course db_course;
            try
            {
                ////will search primary key
                db_course = this.context.courses.Find(courseId);
                if (db_course != null)
                {
                    pocoCourse.CourseId = db_course.course_id;
                    pocoCourse.Description = db_course.course_description;
                    pocoCourse.Title = db_course.course_title;
                    pocoCourse.CourseLevel = (CourseLevel)Enum.Parse(typeof(CourseLevel), db_course.course_level);
                    pocoCourse.Level = db_course.course_level;
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in CourseRepository.FindCourseById: " + e);
            }

            return pocoCourse;
        }
コード例 #4
0
ファイル: CourseRepository.cs プロジェクト: fastily/cse136
        ////probably not necessary
        public List<Course> FindCourseByName(string courseName, ref List<string> errors)
        {
            List<Course> searchResults = new List<Course>();
            IEnumerable<course> db_courses;

            try
            {
                db_courses = this.context.courses.Where(x => x.course_title.Contains(courseName));

                foreach (course db_course in db_courses)
                {
                    POCO.Course pocoCourse = new POCO.Course();

                    pocoCourse.CourseId = db_course.course_id;
                    pocoCourse.Description = db_course.course_description;
                    pocoCourse.Title = db_course.course_title;
                    pocoCourse.CourseLevel = (CourseLevel)Enum.Parse(typeof(CourseLevel), db_course.course_level);
                    pocoCourse.Level = db_course.course_level;
                    searchResults.Add(pocoCourse);
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in CourseRepository.FindCourseByName: " + e);
            }

            return searchResults;
        }
コード例 #5
0
ファイル: CourseRepository.cs プロジェクト: fastily/cse136
        public List<Course> GetCourseList(ref List<string> errors)
        {
            List<POCO.Course> pocoCourseList = new List<POCO.Course>();
            IEnumerable<course> db_courseList;
            try
            {
                db_courseList = this.context.courses;

                foreach (course i_course in db_courseList)
                {
                    var tempPoco = new POCO.Course();
                    tempPoco.CourseId = i_course.course_id;
                    tempPoco.CourseLevel = (CourseLevel)Enum.Parse(typeof(CourseLevel), i_course.course_level);
                    tempPoco.Level = i_course.course_level;
                    tempPoco.Description = i_course.course_description;
                    tempPoco.Title = i_course.course_title;
                    pocoCourseList.Add(tempPoco);
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in CourseRepository.GetCourseList: " + e);
            }

            return pocoCourseList;
        }
コード例 #6
0
ファイル: CourseRepository.cs プロジェクト: fastily/cse136
        public List<Course> GetAllPreReqs(int courseId, ref List<string> errors)
        {
            List<POCO.Course> pocoCourseList = new List<POCO.Course>();
            course db_course = new course();
            IEnumerable<course_preReq> db_preReqCourseList;
            try
            {
                db_preReqCourseList = this.context.course_preReq.Where(x => x.course_id == courseId);

                foreach (course_preReq preReq in db_preReqCourseList)
                {
                    var tempPoco = new POCO.Course();
                    var db_Poco = new course();
                    db_Poco = this.context.courses.Find(preReq.preReq_id);
                    tempPoco.CourseId = db_Poco.course_id;
                    tempPoco.Title = db_Poco.course_title;
                    tempPoco.Description = db_Poco.course_description;
                    tempPoco.Level = db_Poco.course_level;
                    pocoCourseList.Add(tempPoco);
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in CourseRepository.GetAllPreReqs: " + e);
            }

            return pocoCourseList;
        }
コード例 #7
0
ファイル: StudentRepository.cs プロジェクト: fastily/cse136
        public Student GetStudentDetail(string id, ref List<string> errors)
        {
            var conn = new SqlConnection(ConnectionString);
            Student student = null;

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

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

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

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

                student = new Student
                              {
                                  StudentId = dataSet.Tables[0].Rows[0]["student_id"].ToString(),
                                  FirstName = dataSet.Tables[0].Rows[0]["first_name"].ToString(),
                                  LastName = dataSet.Tables[0].Rows[0]["last_name"].ToString(),
                                  Email = dataSet.Tables[0].Rows[0]["email"].ToString(),
                                  Password = dataSet.Tables[0].Rows[0]["password"].ToString()
                              };

                if (dataSet.Tables[1] != null)
                {
                    student.Enrolled = new List<Schedule>();
                    for (var i = 0; i < dataSet.Tables[1].Rows.Count; i++)
                    {
                        var schedule = new Schedule();
                        var course = new Course
                                         {
                                             CourseId = int.Parse(dataSet.Tables[1].Rows[i]["course_id"].ToString()),
                                             Title = dataSet.Tables[1].Rows[i]["course_title"].ToString(),
                                             Description =
                                                 dataSet.Tables[1].Rows[i]["course_description"].ToString()
                                         };
                        schedule.Course = course;

                        schedule.Quarter = dataSet.Tables[1].Rows[i]["quarter"].ToString();
                        schedule.Year = dataSet.Tables[1].Rows[i]["year"].ToString();
                        schedule.Session = dataSet.Tables[1].Rows[i]["session"].ToString();
                        schedule.ScheduleId = Convert.ToInt32(dataSet.Tables[1].Rows[i]["schedule_id"].ToString());
                        student.Enrolled.Add(schedule);
                    }
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in StudentRepository.GetStudentDetail: " + e);
            }
            finally
            {
                conn.Dispose();
            }

            return student;
        }
コード例 #8
0
ファイル: CourseServiceTest.cs プロジェクト: fastily/cse136
        public void AssignPreReqPassTest()
        {
            //// Arranage
            string courseName1 = "Test5";
            string courseName2 = "Test6";
            string courseName3 = "Test7";
            var errors1 = new List<string>();
            var errors2 = new List<string>();
            var mockRepository = new Mock<ICourseRepository>();
            var courseService = new CourseService(mockRepository.Object);
            var course1 = new Course { Title = courseName1 };
            var course2 = new Course { Title = courseName2 };
            var course3 = new Course { Title = courseName3 };
            courseService.InsertCourse(course1, ref errors1);
            courseService.InsertCourse(course2, ref errors1);
            courseService.InsertCourse(course3, ref errors1);

            //// Act
            courseService.AssignPreReq(1, 2, ref errors2);

            //// Assert
            Assert.AreEqual(0, errors2.Count);
        }
コード例 #9
0
ファイル: CourseServiceTest.cs プロジェクト: fastily/cse136
        public void UpdateCourseErrorTest2()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<ICourseRepository>();
            var courseService = new CourseService(mockRepository.Object);
            var course = new Course { Title = string.Empty };

            //// Act
            courseService.UpdateCourse(course, ref errors);

            //// Assert first name cannot be empty
            Assert.AreEqual(1, errors.Count);
        }
コード例 #10
0
ファイル: CourseServiceTest.cs プロジェクト: fastily/cse136
        public void RemoveCourseTest()
        {
            //// Arranage
            var errors = new List<string>();

            Mock<ICourseRepository> mockRepository = new Mock<ICourseRepository>();
            CourseService iserv = new CourseService(mockRepository.Object);

            Course s = new Course { CourseId = 99, Title = "T", Description = "Test" };

            mockRepository.Setup(x => x.RemoveCourse(99, ref errors));

            //// Act
            iserv.DeleteCourse(99, ref errors);

            //// Assert
            mockRepository.Verify(x => x.RemoveCourse(99, ref errors), Times.Once());
        }
コード例 #11
0
ファイル: CourseService.cs プロジェクト: fastily/cse136
        public void InsertCourse(Course course, ref List<string> errors)
        {
            if (course == null)
            {
                errors.Add("Course cannot be null");
                throw new ArgumentException();
            }

            if (string.IsNullOrEmpty(course.Title))
            {
                errors.Add("Course title cannot be null");
                throw new ArgumentException();
            }

            if (this.repository.IsNotDuplicateCourse(course, ref errors))
            {
                this.repository.AddCourse(course, ref errors);
            }
            else
            {
                errors.Add("Duplicate Course");
            }
        }
コード例 #12
0
ファイル: CourseService.cs プロジェクト: fastily/cse136
        public void UpdateCourse(Course course, ref List<string> errors)
        {
            if (course == null)
            {
                errors.Add("Course cannot be null");
                throw new ArgumentException();
            }

            /* see Above
            if (string.IsNullOrEmpty(course.CourseLevel.ToString()))
            {
                errors.Add("Course level cannot be null");
                throw new ArgumentException();
            }
            */

            if (string.IsNullOrEmpty(course.Title))
            {
                errors.Add("Course title cannot be null");
                throw new ArgumentException();
            }

            if (course.CourseId <= 0)
            {
                errors.Add("Course id cannot be null");
                throw new ArgumentException();
            }

            this.repository.UpdateCourse(course, ref errors);
        }
コード例 #13
0
ファイル: CourseController.cs プロジェクト: fastily/cse136
        public string UpdateCourse(Course course)
        {
            var errors = new List<string>();
            var repository = new CourseRepository(this.entities);
            var service = new CourseService(repository);
            service.UpdateCourse(course, ref errors);

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

            return "error";
        }