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
.Presentation
.Controllers
19 using Castle
.MonoRail
.Framework
;
21 using Castle
.Applications
.MindDump
.Model
;
22 using Castle
.Applications
.MindDump
.Services
;
23 using Castle
.Applications
.MindDump
.Adapters
;
26 public class MaintenanceController
: AbstractSecureController
28 private readonly BlogService _blogService
;
29 private readonly AccountService _accountService
;
31 public MaintenanceController(AccountService accountService
, BlogService blogService
)
33 _accountService
= accountService
;
34 _blogService
= blogService
;
37 public void NewEntry()
39 PropertyBag
.Add( "entries", _blogService
.ObtainPosts( ObtainCurrentBlog() ) );
42 public void SaveNewEntry(String title
, String contents
)
44 Blog blog
= ObtainCurrentBlog();
46 Post post
= _blogService
.CreateNewPost(
47 blog
, new Post(title
, contents
, DateTime
.Now
) );
49 Context
.Flash
["message"] = "Your post was created successfully";
51 RenderView("EditEntry");
55 public void EditEntry(long entryid
)
57 PropertyBag
.Add( "entries", _blogService
.ObtainPosts( ObtainCurrentBlog() ) );
58 PropertyBag
.Add( "post", _blogService
.ObtainPost( ObtainCurrentBlog(), entryid
) );
61 public void UpdateEntry(long entryid
, String title
, String contents
)
63 Blog blog
= ObtainCurrentBlog();
65 _blogService
.UpdatePost(
66 blog
, entryid
, new Post(title
, contents
) );
68 Context
.Flash
["message"] = "Your post was updated successfully";
70 RenderView("EditEntry");
74 public void AccountSettings()
76 PropertyBag
.Add("author", ObtainCurrentAuthor() );
79 public void UpdateAccount(String name
, String email
)
81 Author author
= ObtainCurrentAuthor();
85 _accountService
.UpdateAccount(author
);
87 RenderView("NewEntry");
91 public void BlogSettings()
93 PropertyBag
.Add("blog", ObtainCurrentBlog() );
96 public void UpdateBlog(String blogname
, String blogdesc
, String theme
)
98 Blog blog
= ObtainCurrentBlog();
100 blog
.Name
= blogname
;
101 blog
.Description
= blogdesc
;
104 _accountService
.UpdateBlog(blog
);
106 RenderView("NewEntry");
110 // Private utility members
112 private Blog
ObtainCurrentBlog()
114 Author author
= ObtainCurrentAuthor();
115 return author
.Blogs
[0] as Blog
;
118 private Author
ObtainCurrentAuthor()
120 return (Context
.CurrentUser
as PrincipalAuthorAdapter
).Author
;