Beispiel #1
0
		public void Update(Post post)
		{
			using(ISession session = sessionManager.OpenSession())
			{
				session.Update(post);
			}
		}
Beispiel #2
0
		public void FindAll()
		{
			ResetDatabase();

			AuthorDao authorDao = (AuthorDao) Container[ typeof(AuthorDao) ];
			BlogDao blogDao = (BlogDao) Container[ typeof(BlogDao) ];

			Author author = new Author("hamilton verissimo", "hammett", "mypass");
			Blog blog = new Blog("hammett's blog", "my thoughts.. ugh!", "default", author);

			authorDao.Create( author );
			blogDao.Create( blog );

			Post post1 = new Post("My first entry", "This is my first entry", DateTime.Now);
			post1.Blog = blog;
			Post post2 = new Post("My second entry", "This is my second entry", DateTime.Now);
			post2.Blog = blog;

			PostDao postDao = (PostDao) Container[ typeof(PostDao) ];
			postDao.Create(post1);
			postDao.Create(post2);

			IList posts = postDao.Find();
			Assert.AreEqual( 2, posts.Count );
		}
Beispiel #3
0
		public void Create()
		{
			ResetDatabase();

			AuthorDao authorDao = (AuthorDao) Container[ typeof(AuthorDao) ];
			BlogDao blogDao = (BlogDao) Container[ typeof(BlogDao) ];
			PostDao postDao = (PostDao) Container[ typeof(PostDao) ];

			Author author = new Author("hamilton verissimo", "hammett", "mypass");
			Blog blog = new Blog("hammett's blog", "my thoughts.. ugh!", "default", author);
			
			Post post = new Post("My first entry", "This is my first entry", DateTime.Now);
			post.Blog = blog;

			authorDao.Create( author );
			blogDao.Create( blog );
			postDao.Create( post );

			IList posts = postDao.Find();
			Assert.AreEqual( 1, posts.Count );

			Post comparisson = (Post) posts[0];
			Assert.AreEqual( post.Title, comparisson.Title );
			Assert.AreEqual( post.Contents, comparisson.Contents );
		}
Beispiel #4
0
		public Post Create(Post post)
		{
			using(ISession session = sessionManager.OpenSession())
			{
				session.Save(post);

				return post;
			}
		}
Beispiel #5
0
		public Post CreateNewPost(Blog blog, Post post)
		{
			try
			{
				post.Blog = blog;
				return _postDao.Create(post);
			}
			catch(Exception ex)
			{
				throw new ApplicationException("Could not create post", ex);
			}
		}
Beispiel #6
0
		public void UpdatePost(Blog blog, long postId, Post post)
		{
			try
			{
				Post originalPost = ObtainPost(blog, postId);

				originalPost.Title = post.Title;
				originalPost.Contents = post.Contents;
			
				_postDao.Update(originalPost);
			}
			catch(Exception ex)
			{
				throw new ApplicationException("Could not update post", ex);
			}
		}