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 BinderSample
.Web
.Controllers
18 using System
.Collections
;
20 using Castle
.MonoRail
.Framework
;
22 using BinderSample
.Web
.Model
;
26 public class Approach1Controller
: SmartDispatcherController
30 PropertyBag
.Add("publishers", Publisher
.FindAll());
33 public void EditPublisher(int publisherId
)
35 PropertyBag
.Add("publisher", Publisher
.Find(publisherId
));
38 [AccessibleThrough(Verb
.Post
)]
39 public void Update([DataBind("publisher")] Publisher formpublisher
,
40 int[] bookids
, String
[] booknames
, String
[] bookauthors
)
42 Publisher publisher
= Publisher
.Find(formpublisher
.Id
);
43 publisher
.Name
= formpublisher
.Name
;
45 IDictionary books
= new Hashtable(); int index
= 0;
47 foreach(int id
in bookids
)
49 Book book
= new Book();
52 book
.Name
= booknames
[index
];
53 book
.Author
= bookauthors
[index
];
60 foreach(Book book
in publisher
.Books
)
62 Book formBook
= books
[book
.Id
] as Book
;
64 book
.Name
= formBook
.Name
;
65 book
.Author
= formBook
.Author
;
72 Flash
["message"] = "Changes saved";
74 RedirectToAction("EditPublisher", "publisherId=" + publisher
.Id
);