Added RedirectUsingNamedRoute
[castle.git] / Samples / MindDump / Castle.Applications.MindDump / Dao / AuthorDao.cs
blob0eb8dd82a8951c39abd85b06711e1e092a6b6d98
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 AuthorDao
27 private readonly ISessionManager sessionManager;
29 public AuthorDao(ISessionManager sessionManager)
31 this.sessionManager = sessionManager;
34 public Author Create(Author author)
36 using(ISession session = sessionManager.OpenSession())
38 if (author.Blogs == null)
40 author.Blogs = new ArrayList();
43 session.Save(author);
46 return author;
49 public void Update(Author author)
51 using(ISession session = sessionManager.OpenSession())
53 session.Update(author);
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 Author");
69 public IList Find()
71 using(ISession session = sessionManager.OpenSession())
73 return session.Find("from Author");
77 public Author Find(String login)
79 using(ISession session = sessionManager.OpenSession())
81 IList list = session.Find(
82 "from Author as a where a.Login=:name", login, NHibernateUtil.String);
84 if (list.Count == 1)
86 Author author = list[0] as Author;
88 if (author.Blogs.Count == 1)
90 // We just reference the blog
91 // to load it
92 Blog blog = author.Blogs[0] as Blog;
95 return author;
97 else
99 return null;