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 BlogMaintenanceService
26 private PostDao _postDao
;
27 private BlogDao _blogDao
;
28 private AuthorDao _authorDao
;
30 public BlogMaintenanceService(AuthorDao authorDao
, BlogDao blogDao
, PostDao postDao
)
32 _authorDao
= authorDao
;
37 public Post
CreateNewPost(Blog blog
, Post post
)
43 return _postDao
.Create(post
);
47 throw new ApplicationException("Could not create post", ex
);
51 public void UpdatePost(Blog blog
, long postId
, Post post
)
53 Post originalPost
= ObtainPost(blog
, postId
);
55 originalPost
.Title
= post
.Title
;
56 originalPost
.Contents
= post
.Contents
;
60 _postDao
.Update(originalPost
);
64 throw new ApplicationException("Could not update post", ex
);
68 public Post
ObtainPost( Blog blog
, long postId
)
72 Post post
= _postDao
.Find(postId
);
76 if (post
.Blog
.Id
!= blog
.Id
)
78 throw new ApplicationException("The post requested belongs " +
79 "to a different blog");
85 catch(ApplicationException ex
)
91 throw new ApplicationException("Could not find post", ex
);
95 public IList
ObtainPosts(Blog blog
)
97 return _postDao
.Find(blog
);
100 public Blog
ObtainBlogByAuthorName(string authorName
)
102 Author author
= _authorDao
.Find(authorName
);
109 return author
.Blogs
[0] as Blog
;