Added RedirectUsingNamedRoute
[castle.git] / Samples / MindDump / Castle.Applications.MindDump / Dao / BlogDao.cs
blobb144c785daeb783f44644ae10ddc8f5851e80a1f
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.Dao
17 using System;
18 using System.Collections;
20 using Castle.Applications.MindDump.Model;
21 using Castle.Facilities.NHibernateIntegration;
23 using NHibernate;
25 public class BlogDao
27 private readonly ISessionManager sessionManager;
29 public BlogDao(ISessionManager sessionManager)
31 this.sessionManager = sessionManager;
34 public Blog Create(Blog blog)
36 using(ISession session = sessionManager.OpenSession())
38 if (blog.Posts == null)
40 blog.Posts = new ArrayList();
43 session.Save(blog);
46 return blog;
49 public void Update(Blog blog)
51 using(ISession session = sessionManager.OpenSession())
53 session.Update(blog);
57 /// <summary>
58 /// Usually will be invoked only by the
59 /// test cases
60 /// </summary>
61 public void DeleteAll()
63 using(ISession session = sessionManager.OpenSession())
65 session.Delete("from Blog");
69 public IList Find()
71 using(ISession session = sessionManager.OpenSession())
73 return session.Find("from Blog");
77 public Blog Find(String blogName)
79 using(ISession session = sessionManager.OpenSession())
81 IList list = session.Find(
82 "from Blog as a where a.Name=:name", blogName, NHibernateUtil.String);
84 if (list.Count == 1)
86 return list[0] as Blog;
88 else
90 return null;
95 public IList FindLatest(int howMany)
97 using(ISession session = sessionManager.OpenSession())
99 IList list = session.Find("from Blog order by id desc");
101 if (list.Count > howMany)
103 list = ListUtil.Limit(howMany, list);
106 return list;