예제 #1
0
 public void Update(Article entity)
 {
     using (var session = NHibernateHelper.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             try
             {
                 session.Update(entity);
                 transaction.Commit();
             }
             catch (ADOException)
             {
                 throw new Exception("Unable to update article");
             }
         }
     }
 }
예제 #2
0
 public void Create(Article entity)
 {
     using (var session = NHibernateHelper.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             try
             {
                 session.Save(entity);
                 transaction.Commit();
             }
             catch (NHibernate.ADOException)
             {
                 throw new Exception("Defined article already exists");
             }
         }
     }
 }
예제 #3
0
 public void Delete(Article entity)
 {
     using (var session = NHibernateHelper.OpenSession())
     {
         using (ITransaction transaction = session.BeginTransaction())
         {
             try
             {
                 session.Delete(entity);
                 transaction.Commit();
             }
             catch (ADOException)
             {
                 throw new Exception("Defined article doesn't exist");
             }
         }
     }
 }
        public void A_CreateArticle()
        {
            IRepository<Category> categoryRep = new CategoryRepository();
            Category category = categoryRep.Read(1);

            IRepository<Author> authorRep = new AuthorRepository();
            Author author = authorRep.Read(1);

            #region Read photo from file

            FileInfo fileInfo = new FileInfo(@"..\..\..\..\..\DAL\Resources\Chrysanthemum.jpg");
            FileStream fileStream = fileInfo.OpenRead();
            long length = fileStream.Length;

            byte[] photoData = null;

            if (length > 0)
            {
                photoData = new byte[length];
            }

            fileStream.Read(photoData, 0, Convert.ToInt32(length));
            fileStream.Close();

            #endregion

            Photo photo1 = new Photo(PhotoType.Large, "testName", photoData);
            Photo photo2 = new Photo(PhotoType.Medium, "testName", photoData);
            Photo photo3 = new Photo(PhotoType.Small, "testName", photoData);
            List<Photo> photos = new List<Photo>();
            photos.Add(photo1);
            photos.Add(photo2);
            photos.Add(photo3);

            Article article = new Article("testName", "testName", "testName", "testName", "testName", "testName", "testName", true, true, true, category, author, photos);

            IRepository<Article> articleRep = new ArticleRepository();
            articleRep.Create(article);
        }