Reverted accidental checkin
[castle.git] / Samples / MindDump / Castle.Applications.MindDump / Presentation / Controllers / MaintenanceController.cs
blobe2d0ea40ad6ec5eb341a8e2c13ac44659212744e
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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
17 using System;
19 using Castle.MonoRail.Framework;
21 using Castle.Applications.MindDump.Model;
22 using Castle.Applications.MindDump.Services;
23 using Castle.Applications.MindDump.Adapters;
25 [Layout("private")]
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");
52 EditEntry( post.Id );
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");
71 EditEntry( entryid );
74 public void AccountSettings()
76 PropertyBag.Add("author", ObtainCurrentAuthor() );
79 public void UpdateAccount(String name, String email)
81 Author author = ObtainCurrentAuthor();
83 author.Name = name;
85 _accountService.UpdateAccount(author);
87 RenderView("NewEntry");
88 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;
102 blog.Theme = theme;
104 _accountService.UpdateBlog(blog);
106 RenderView("NewEntry");
107 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;