Changed to use Authenticate asp.net event instead of Authorize
[castle.git] / Samples / MonoRail / BinderSample / BinderSample.Web / Controllers / Approach1Controller.cs
blob410f826e297c6a9dd188e364e740e8d44e373412
1 // Copyright 2004-2007 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 BinderSample.Web.Controllers
17 using System;
18 using System.Collections;
20 using Castle.MonoRail.Framework;
22 using BinderSample.Web.Model;
25 [Layout("scaffold")]
26 public class Approach1Controller : SmartDispatcherController
28 public void Index()
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();
51 book.Id = id;
52 book.Name = booknames[index];
53 book.Author = bookauthors[index];
55 books[id] = book;
57 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;
67 book.Save();
70 publisher.Save();
72 Flash["message"] = "Changes saved";
74 RedirectToAction("EditPublisher", "publisherId=" + publisher.Id);