1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.Applications
.MindDump
.Services
18 using System
.Collections
;
20 using Castle
.Applications
.MindDump
.Dao
;
21 using Castle
.Applications
.MindDump
.Model
;
24 public class BlogService
26 private PostDao _postDao
;
27 private BlogDao _blogDao
;
28 private AuthorDao _authorDao
;
29 private int _latestBlogsCount
= 10;
30 private int _latestPostCount
= 10;
32 public BlogService(AuthorDao authorDao
, BlogDao blogDao
, PostDao postDao
)
34 _authorDao
= authorDao
;
40 /// This value can be optionally adjusted using
41 /// the configuration associated with the kernel
43 public int LatestBlogsCount
45 get { return _latestBlogsCount; }
46 set { _latestBlogsCount = value; }
50 /// This value can be optionally adjusted using
51 /// the configuration associated with the kernel
53 public int LatestPostCount
55 get { return _latestPostCount; }
56 set { _latestPostCount = value; }
59 public Post
CreateNewPost(Blog blog
, Post post
)
64 return _postDao
.Create(post
);
68 throw new ApplicationException("Could not create post", ex
);
72 public void UpdatePost(Blog blog
, long postId
, Post post
)
76 Post originalPost
= ObtainPost(blog
, postId
);
78 originalPost
.Title
= post
.Title
;
79 originalPost
.Contents
= post
.Contents
;
81 _postDao
.Update(originalPost
);
85 throw new ApplicationException("Could not update post", ex
);
89 public Post
ObtainPost( Blog blog
, long postId
)
93 Post post
= _postDao
.Find(postId
);
97 if (post
.Blog
.Id
!= blog
.Id
)
99 throw new ApplicationException("The post requested belongs " +
100 "to a different blog");
106 catch(ApplicationException ex
)
112 throw new ApplicationException("Could not find post", ex
);
116 public IList
ObtainPosts(Blog blog
)
118 return _postDao
.Find(blog
);
121 public Blog
ObtainBlogByAuthorName(string authorName
)
123 Author author
= _authorDao
.Find(authorName
);
130 return author
.Blogs
[0] as Blog
;
133 public IList
ObtainLatestBlogs()
135 return _blogDao
.FindLatest(10);
138 public IList
ObtainLatestPosts()
140 return _postDao
.FindLatest(10);