Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.ActiveRecordSupport / Scaffold / EditAction.cs
blob9e2ecaa1450b5b8f78c05c7b6f54ce551f4ca44f
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 Castle.MonoRail.ActiveRecordSupport.Scaffold
17 using System;
18 using Castle.ActiveRecord;
19 using Castle.Components.Common.TemplateEngine;
20 using Castle.MonoRail.Framework;
22 /// <summary>
23 /// Renders an edit form
24 /// </summary>
25 /// <remarks>
26 /// Searchs for a template named <c>edit{name}</c>
27 /// </remarks>
28 public class EditAction : AbstractScaffoldAction
30 public EditAction(Type modelType, ITemplateEngine templateEngine, bool useModelName, bool useDefaultLayout) :
31 base(modelType, templateEngine, useModelName, useDefaultLayout)
35 protected override string ComputeTemplateName(IControllerContext controller)
37 return controller.Name + "\\edit";
40 protected override void PerformActionProcess(IEngineContext engineContext, IController controller, IControllerContext controllerContext)
42 base.PerformActionProcess(engineContext, controller, controllerContext);
44 object idVal = CommonOperationUtils.ReadPkFromParams(controllerContext.CustomActionParameters, engineContext.Request, ObtainPKProperty());
46 try
48 if (!engineContext.Flash.Contains(Model.Type.Name))
50 object instance = ActiveRecordMediator.FindByPrimaryKey(Model.Type, idVal, true);
51 controllerContext.PropertyBag["instance"] = instance;
52 controllerContext.PropertyBag[Model.Type.Name] = instance;
55 controllerContext.PropertyBag["prefix"] = Model.Type.Name;
56 controllerContext.PropertyBag["id"] = idVal;
58 catch(Exception ex)
60 throw new ScaffoldException("Could not obtain instance by using this id", ex);
64 protected override void RenderStandardHtml(IEngineContext engineContext, IController controller, IControllerContext controllerContext)
66 SetUpHelpers(engineContext, controller, controllerContext);
67 RenderFromTemplate("edit.vm", engineContext, controller, controllerContext);