/* ---- [ cut here: next file 'Controller.auto.cs'] ---------------- */ //------------------------------------------------------------------ // // Application Description Framework // Controller.auto.cs // // (c) 2007 Cygnet Solutions Ltd // // Controller for auto-generated forms for editing s // Automatically generated from application description using // adl2controllerclass.xsl version // // This file is automatically generated; DO NOT EDIT IT. // //------------------------------------------------------------------ using System; using System.Data; using System.Collections.Generic; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using Castle.MonoRail.Framework.Helpers; using Cygnet.Web.Helpers; using Cygnet.Web.Controllers; using NHibernate; using NHibernate.Expression; using Castle.MonoRail.Framework; using SRU.Hospitality.Entities; using SRU.Hospitality.Helpers; using ADL.Exceptions; using Iesi.Collections.Generic; namespace { /// <summary> /// Automatically generated partial controller class following 'thin controller' /// strategy, for entity . Note that part of this /// class may be defined in a separate file called /// Controller.manual.cs, q.v. /// /// DO NOT EDIT THIS FILE! /// </summary> [ Helper(typeof(ShuffleWidgetHelper), "ShuffleWidgetHelper"), ] public partial class Controller : BaseController { /// <summary> /// Store the record represented by the parameters passed in an HTTP service /// Without Id -> it's new, I create a new persistent object; /// With Id -> it's existing, I update the existing persistent object. /// NOTE: Should only be called from a handler for method 'POST', never 'GET'. /// </summary> private void Store() { ISession hibernator = NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], Session[NHibernateHelper.PASSTOKEN]); List<string> messages = new List<string>(); . record; string id = Form[""]; if ( String.IsNullOrEmpty( id)) { /* it's new, create persistent object */ record = new .(Form[] , ); /* perform any domain knowledge behaviour on the new record * after instantiation */ record.AfterCreationHook( hibernator); messages.Add( "New record created"); } else { /* it's existing, retrieve it */ record = hibernator.CreateCriteria(typeof()) .Add(Expression.Eq("", Int32.Parse(id))) .UniqueResult<.>(); } if ( record != null) { try { /* actually update the record */ BindObjectInstance( record, ParamStore.Form, "instance"); /* for properties of type 'entity', it should not be necessary to do anything * special - BindObjectInstance /should/ do it all. Unfortunately it sometimes * doesn't, and I haven't yet characterised why not. TODO: Fix this! */ record. = hibernator.CreateCriteria(typeof()) .Add(Expression.Eq(" ", Int32.Parse(Form[""]))) .UniqueResult<.>(); /* to update a link table which has no other data than the near and far keys, it is * sufficient to smash the existing values and create new ones. It's also a lot easier! */ string[] = Form.GetValues( ""); if ( != null) { /* update the linking table for my ; first smash the old values */ if ( != null) { .Clear(); } else { = new HashedSet<>(); } /* then reinstate the values from the indexes passed */ foreach ( string index in ) { .Add( hibernator.CreateCriteria(typeof()) .Add(Expression.Eq("Id", Int32.Parse(index))) .UniqueResult<.>()); } } /* with a list we cannot just smash the old values! Instead we need to check * each one and exclude it if no longer required */ if ( Form.GetValues( "") != null) { string[] = Form.GetValues( ""); /* updating child records; first remove any not on the submitted list */ foreach ( item in record.) { String itemId = item.Key.ToString(); bool found = false; foreach ( string index in ) { if ( index.Equals( itemId)) { found = true; } } if ( ! found) { record..Remove( item); } } /* then add any on the included list which are not already members */ foreach ( string index in ) { item = hibernator.CreateCriteria(typeof()) .Add(Expression.Eq("Id", Int32.Parse(index))) .UniqueResult<.>(); if ( ! record..Contains( item)) { record..Add( item); } } } /* perform any domain knowledge behaviour on the record prior to updating */ record.BeforeUpdateHook( hibernator); /* write the record to the database, in order to guarantee we have a valid key */ hibernator.Save(record); hibernator.Flush(); /* perform any domain knowledge behaviour on the record after updating */ record.AfterUpdateHook( hibernator); messages.Add( "Record saved successfully"); } catch ( DataSuitabilityException dse) { AddError( dse.Message); } catch ( ApplicationException axe) { AddError( axe.Message); } PropertyBag["messages"] = messages; PropertyBag["username"] = Session[ NHibernateHelper.USERTOKEN]; PropertyBag["instance"] = record; RenderViewWithFailover("", ""); } else { throw new Exception( String.Format( "No record of type with key value {0} found", id)); } } /// <summary> /// Actually delete the selected record /// </summary> [AccessibleThrough(Verb.Get)] public void Delete() { ISession hibernator = NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], Session[NHibernateHelper.PASSTOKEN]); string id = Params[""]; string reallydelete = Params["reallydelete"]; if ( "true".Equals( reallydelete)) { record = hibernator.CreateCriteria(typeof()) .Add(Expression.Eq("", Int32.Parse(id))) .UniqueResult<.>(); if ( record != null) { record.BeforeDeleteHook( hibernator); hibernator.Delete( hibernator.CreateCriteria(typeof()) .Add(Expression.Eq("", Int32.Parse(id))) .UniqueResult<.>()); hibernator.Flush(); } else { throw new ApplicationException( "No such record?"); } } InternalShowList(); Redirect( FormsAuthentication.DefaultUrl); } /// <summary> /// list all instances of this entity to allow the user to select one for editing /// this method invokes the default list view - which is probably what you want unless /// you've a special reason for doing something different /// </summary> public void InternalShowList() { InternalShowList( ""); } /// <summary> /// list all instances of this entity to allow the user to select one for editing /// </summary> /// <param name="view">The name of the list view to show</param> public void InternalShowList( String view) { ISession hibernator = NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], Session[NHibernateHelper.PASSTOKEN]); IList<> instances = hibernator.CreateCriteria(typeof()) .List<>(); PropertyBag["username"] = Session[ NHibernateHelper.USERTOKEN]; PropertyBag["instances"] = PaginationHelper.CreatePagination( this, instances, 25); RenderViewWithFailover(view + ".vm", view + ".auto.vm"); } } } if ( Form[ "" ] == null) { AddError( "You must supply a value for " ); } "" /// <summary> /// Handle the submission of the form named /// </summary> [AccessibleThrough(Verb.Post)] public void ( ) { string command = Form[ "command"]; if ( command == null) { throw new Exception( "No command?"); } else if ( command.Equals( "")) { /* NOTE: You must write an implementation of this verb in a manually maintained partial class file for this class */ (); } else if ( command.Equals( "delete")) { ISession hibernator = NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], Session[NHibernateHelper.PASSTOKEN]); string id = Form[""]; PropertyBag["username"] = Session[ NHibernateHelper.USERTOKEN]; PropertyBag["instance"] = hibernator.CreateCriteria(typeof()) .Add(Expression.Eq("", Int32.Parse(id))) .UniqueResult<.>(); RenderViewWithFailover( "maybedelete.vm", "maybedelete.auto.vm"); } else if ( command.Equals( "store")) { Store(); } else { throw new Exception( String.Format("Unrecognised command '{0}'", command)); } } /// <summary> /// Show the form named , with no content /// </summary> [AccessibleThrough(Verb.Get)] public void ( ) { ISession hibernator = NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], Session[NHibernateHelper.PASSTOKEN]); PropertyBag["username"] = Session[ NHibernateHelper.USERTOKEN]; RenderViewWithFailover("", ""); } /// <summary> /// Show the form named , containing the indicated record /// </summary> /// <param name="">the key value of the record to show</param> [AccessibleThrough(Verb.Get)] public void ( Int32 ) { ISession hibernator = NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], Session[NHibernateHelper.PASSTOKEN]); . record = hibernator.CreateCriteria(typeof()) .Add(Expression.Eq("", Id)) .UniqueResult<.>(); PropertyBag["username"] = Session[ NHibernateHelper.USERTOKEN]; PropertyBag["instance"] = record; RenderViewWithFailover("", ""); } /// <summary> /// list all instances of this entity to allow the user to select one /// this method invokes the named view. /// </summary> public void () { InternalShowList( ""); } /* produce a list of to populate the menu for */ /* produce a list of to populate the LHS of the shuffle for */ /* produce a list of to populate the multi-select for */ PropertyBag[""] = hibernator.CreateCriteria(typeof()) .List<>();