Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / TestSiteARSupport / Controllers / AccountController.cs
blobae8b9977e5a56f502d1c62c2fefd5a8da64b8c5c
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 TestSiteARSupport.Controllers
17 using Castle.ActiveRecord;
18 using Castle.Components.Binder;
19 using Castle.Components.Validator;
20 using Castle.MonoRail.ActiveRecordSupport;
21 using Castle.MonoRail.Framework;
23 using TestSiteARSupport.Model;
25 [Layout("default")]
26 public class AccountController : ARSmartDispatcherController
28 public void New()
30 PropertyBag["accounttype"] = typeof(Account);
31 PropertyBag.Add("licenses", ProductLicense.FindAll());
32 PropertyBag.Add("permissions", AccountPermission.FindAll());
33 PropertyBag.Add("users", User.FindAll());
36 public void New2()
38 PropertyBag["accounttype"] = typeof(Account);
39 PropertyBag.Add("licenses", ProductLicense.FindAll());
40 PropertyBag.Add("permissions", AccountPermission.FindAll());
41 PropertyBag.Add("users", User.FindAll());
44 [AccessibleThrough(Verb.Post)]
45 public void Insert([ARDataBind("account", AutoLoad=AutoLoadBehavior.OnlyNested, Validate=true)] Account account)
47 ErrorList errorList = BoundInstanceErrors[account];
48 ErrorSummary summary = GetErrorSummary(account);
50 PropertyBag.Add("errorlist", errorList);
52 if (errorList.Count == 0)
54 account.Create();
56 PropertyBag.Add("account", account);
60 public void Edit(int id)
62 if (Flash.Contains("account"))
64 PropertyBag["account"] = Flash["account"];
66 else
68 PropertyBag["account"] = ActiveRecordMediator<Account>.FindByPrimaryKey(id);
71 PropertyBag.Add("licenses", ProductLicense.FindAll());
72 PropertyBag.Add("permissions", AccountPermission.FindAll());
73 PropertyBag.Add("users", User.FindAll());
76 public void Edit2(int id)
78 if (!Flash.Contains("account"))
80 PropertyBag["account"] = ActiveRecordMediator<Account>.FindByPrimaryKey(id);
83 PropertyBag.Add("licenses", ProductLicense.FindAll());
84 PropertyBag.Add("permissions", AccountPermission.FindAll());
85 PropertyBag.Add("users", User.FindAll());
88 [AccessibleThrough(Verb.Post)]
89 public void Update([ARDataBind("account", AutoLoad=AutoLoadBehavior.NullIfInvalidKey, Expect="account.Permissions,account.Users", Validate=true)] Account account)
91 ErrorList errorList = BoundInstanceErrors[account];
92 ErrorSummary summary = GetErrorSummary(account);
94 PropertyBag.Add("errorlist", errorList);
95 PropertyBag.Add("summary", summary);
97 if (errorList.Count == 0)
99 account.Update();
101 PropertyBag.Add("account", account);
105 public void RemoveConfirm([ARFetch("id", false, true)] Account account)
107 PropertyBag.Add("account", account);
110 [AccessibleThrough(Verb.Post)]
111 public void Delete([ARFetch("account", false, true)] Account account)
113 account.Delete();