Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / Experiments / Generator / Generators / Scaffold / Templates / Controller.cs
blob5800e4fde772e44231042a5dd66fe74f807a2feb
1 using System;
2 using Castle.MonoRail.Framework;
3 using Castle.MonoRail.Framework.Helpers;
4 using Castle.MonoRail.ActiveRecordSupport;
5 using <%= ModelsNamespace %>;
6 using <%= HelpersNamespace %>;
7 <% if Area != null: %>
8 using <%= ApplicationControllerNamespace %>;
9 <% end %>
11 namespace <%= Namespace %>
13 /// <summary>
14 /// <%= PluralHumanName %> controller
15 /// </summary>
16 [Layout("<%= ControllerFileName %>"), Helper(typeof(ScaffoldHelper))]
17 <% if Area != null: %>
18 [ControllerDetails(Area="<%= Area %>")]
19 <% end %>
20 public class <%= ControllerName %>Controller : ApplicationController
22 public void Index()
24 RedirectToAction("list");
27 public void List()
29 PropertyBag["<%= PluralVarName %>"] = PaginationHelper.CreatePagination(<%= ClassName %>.FindAll(), 10);
32 public void View(int id)
34 PropertyBag["<%= VarName %>"] = <%= ModelClassName %>.Find(id);
37 public void Edit(int id)
39 PropertyBag["<%= VarName %>"] = <%= ModelClassName %>.Find(id);
42 public void Update([ARDataBind("<%= VarName %>", AutoLoadBehavior.Always)] <%= ModelClassName %> <%= VarName %>)
44 if (<%= VarName %>.IsValid())
46 <%= VarName %>.Update();
47 Flash["edited"] = <%= VarName %>.Id;
48 RedirectToAction("list");
50 else
52 PropertyBag["<%= VarName %>"] = <%= VarName %>;
53 RenderView("edit");
57 public void New()
59 PropertyBag["<%= VarName %>"] = new <%= ModelClassName %>();
62 public void Create([DataBind("<%= VarName %>")] <%= ModelClassName %> <%= VarName %>)
64 if (<%= VarName %>.IsValid())
66 <%= VarName %>.Create();
67 Flash["edited"] = <%= VarName %>.Id;
68 RedirectToAction("list");
70 else
72 PropertyBag["<%= VarName %>"] = <%= VarName %>;
73 RenderView("new");
77 public void Delete(int id)
79 <%= ModelClassName %>.Find(id).Delete();
80 CancelView();