public void DeleteCourse(Course course)
        {
            course = CourseDao.GetCourseByName(course.Name);

            if (course != null)
            {
                CourseDao.DeleteCourse(course);
            }
        }
 public void DeleteEmployee(Course course)
 {
     try
     {
         CourseService.DeleteCourse(course);
     }
     catch (Exception)
     {
         throw new HttpResponseException(HttpStatusCode.InternalServerError);
     }
 }
        public Course AddCourse(Course course)
        {
            CheckCourseIsNotNullThrowException(course);

            try
            {
                return CourseService.AddCourse(course);
            }
            catch (Exception)
            {
                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }
        }
        public Course UpdateCourse(Course course)
        {
            CheckCourseIsNullThrowException(course);

            try
            {
                CourseService.UpdateCourse(course);
                return CourseService.GetCourseByName(course.Name);
            }
            catch (Exception)
            {
                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }
        }
        public void TestCourseDao_AddCourse()
        {
            Course course = new Course();
            course.Id = "UnitTests";
            course.Name = "單元測試";
            course.Description = "請做出單元測試";
            CourseDao.AddCourse(course);

            Course dbCourse = CourseDao.GetCourseByName(course.Name);
            Assert.IsNotNull(dbCourse);
            Assert.AreEqual(course.Name, dbCourse.Name);

            Console.WriteLine("課程編號為 = " + dbCourse.Id);
            Console.WriteLine("課程名稱為 = " + dbCourse.Name);
            Console.WriteLine("課程描述為 = " + dbCourse.Description);

            CourseDao.DeleteCourse(dbCourse);
            dbCourse = CourseDao.GetCourseByName(course.Name);
            Assert.IsNull(dbCourse);
        }
 public void UpdateCourse(Course course)
 {
     CourseDao.UpdateCourse(course);
 }
 public Course AddCourse(Course course)
 {
     CourseDao.AddCourse(course);
     return GetCourseByName(course.Name);
 }
        /// <summary>
        ///     檢查課程資料是否存在,如果不存在則拋出錯誤.
        /// </summary>
        /// <param name="course">
        ///     課程資料.
        /// </param>
        private void CheckCourseIsNullThrowException(Course course)
        {
            Course dbCourse = CourseService.GetCourseById(course.Id);

            if (dbCourse == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
        }