1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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 TestSiteNVelocity
.Controllers
19 using Castle
.MonoRail
.Framework
;
22 /// Same as <see cref="SmartController"/> but using
23 /// BindObject methods
25 public class Smart2Controller
: SmartDispatcherController
27 public void SimpleBind()
29 Order order
= (Order
) BindObject(typeof(Order
), "order");
30 RenderText(String
.Format("incoming {0}", order
.ToString()));
33 public void SimpleBindArray()
35 Order
[] orders
= (Order
[]) BindObject(typeof(Order
[]), "orders");
39 RenderText("Null array shouldn't be returned by databinder");
43 RenderText(String
.Format("incoming {0}", orders
.Length
));
47 public void ComplexBind()
49 Order order
= (Order
) BindObject(typeof(Order
), "order");
50 Person person
= (Person
) BindObject(typeof(Person
), "person");
52 RenderText(String
.Format("incoming {0} {1}", order
.ToString(), person
.ToString()));
55 public void ComplexBindExcludePrice()
57 Order order
= (Order
) BindObject(ParamStore
.Params
, typeof(Order
), "order", "order.Price", null);
58 Person person
= (Person
) BindObject(typeof(Person
), "person");
60 RenderText(String
.Format("incoming {0} {1}", order
.ToString(), person
.ToString()));
63 public void ComplexBindExcludeName()
65 Order order
= (Order
) BindObject(ParamStore
.Params
, typeof(Order
), "order", "order.Name", null);
66 Person person
= (Person
) BindObject(typeof(Person
), "person");
68 RenderText(String
.Format("incoming {0} {1}", order
.ToString(), person
.ToString()));
71 public void ComplexBindWithPrefix()
73 Order order
= (Order
) BindObject(typeof(Order
), "order");
74 Person person
= (Person
) BindObject(typeof(Person
), "person");
76 RenderText(String
.Format("incoming {0} {1}", order
.ToString(), person
.ToString()));
79 public void FillingBehavior()
81 System
.Threading
.Thread
.CurrentThread
.CurrentCulture
= System
.Globalization
.CultureInfo
.InvariantCulture
;
83 ClassWithInitializers clazz
= (ClassWithInitializers
) BindObject(typeof(ClassWithInitializers
), "abc");
85 RenderText(String
.Format("incoming {0} {1} {2}", clazz
.Name
, clazz
.Date1
.ToShortDateString(), clazz
.Date2
.ToShortDateString()));
88 public void NullableConversion2()
90 Movement movement
= (Movement
) BindObject(typeof(Movement
), "mov");
92 RenderText(String
.Format("incoming {0} {1}", movement
.Name
, movement
.Amount
));
95 public void ArrayBinding()
97 User2 user
= (User2
) BindObject(typeof(User2
), "user");
99 RenderText(user
.ToString());
101 foreach(int id
in user
.Roles
)
103 RenderText(" " + id
);
105 foreach(int id
in user
.Permissions
)
107 RenderText(" " + id
);
111 public void CalculateUtilizationByDay()
113 TimePoint tp1
= (TimePoint
) BindObject(typeof(TimePoint
), "tp1");
114 TimePoint tp2
= (TimePoint
) BindObject(typeof(TimePoint
), "tp2");
116 RenderText(tp1
.ToString());
117 RenderText(tp2
.ToString());