public Directory UpdateDirectory(Directory directory)
        {
            CheckDirectoryIsNullThrowException(directory);

                DirectoryService.UpdateDirectory(directory);
                return DirectoryService.GetDirectoryByName(directory.FriendDirectory_name);
           
        }
        public void DeleteDirectory(Directory directory)
        {
            directory = DirectoryDao.GetDirectoryByName(directory.FriendDirectory_name);

            if (directory != null)
            {
                DirectoryDao.DeleteDirectory(directory);
            }
        }
        public Directory AddDirectory(Directory directory)
        {
            CheckDirectoryIsNotNullThrowException(directory);

            
                return DirectoryService.AddDirectory(directory);
            
            
        }
 public void DeleteDirectory(Directory directory)
 {
     try
     {
         DirectoryService.DeleteDirectory(directory);
     }
     catch (Exception)
     {
         throw new HttpResponseException(HttpStatusCode.InternalServerError);
     }
 }
        public void TestDirectoryService_AddDirectory()
        {

            Directory directory = new Directory();
            directory.FriendDirectory_id = 1;
            directory.FriendDirectory_name = "單元測試";
            directory.FriendDirectory_gender = "請做出單元測試";
            DirectoryService.AddDirectory(directory);

            Directory dbDirectory = DirectoryService.GetDirectoryByName(directory.FriendDirectory_name);
            Assert.IsNotNull(dbDirectory);
            Assert.AreEqual(directory.FriendDirectory_name, dbDirectory.FriendDirectory_name);

            Console.WriteLine("聯絡人編號為 = " + dbDirectory.FriendDirectory_id);
            Console.WriteLine("聯絡人名稱為 = " + dbDirectory.FriendDirectory_name);
            Console.WriteLine("聯絡人性別為 = " + dbDirectory.FriendDirectory_gender);

            DirectoryService.DeleteDirectory(dbDirectory);
            dbDirectory = DirectoryService.GetDirectoryByName(directory.FriendDirectory_name);
            Assert.IsNull(dbDirectory);
        }
 public void UpdateDirectory(Directory directory)
 {
     DirectoryDao.UpdateDirectory(directory);
 }
 public Directory AddDirectory(Directory directory)
 {
     DirectoryDao.AddDirectory(directory);
     return GetDirectoryByName(directory.FriendDirectory_name);
 }
        /// <summary>
        ///     檢查課程資料是否存在,如果不存在則拋出錯誤.
        /// </summary>
        /// <param name="directory">
        ///     課程資料.
        /// </param>
        private void CheckDirectoryIsNullThrowException(Directory directory)
        {
            Directory dbCourse = DirectoryService.GetDirectoryById(directory.FriendDirectory_id);

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