/* ---- [ cut here: next file '.auto.cs'] ---------------- */ //------------------------------------------------------------------ // // // // // (c) 2007 Cygnet Solutions Ltd // // Automatically generated abstract super class for controllers for the // application; generated using // adl2controllerclasses.xslt version // // // // This file is automatically generated; DO NOT EDIT IT. // //------------------------------------------------------------------ using System; using System.Data; using System.Collections.Generic; using NHibernate; using NHibernate.Expression; using Cygnet.Web.Controllers; using Cygnet.Web.Helpers; using Castle.MonoRail.Framework; using ; namespace { /// <summary> /// Automatically generated abstract super class for controllers for the /// application /// /// DO NOT EDIT THIS FILE! /// </summary> [ Helper(typeof(SecurityHelper), "SecurityHelper") ] public abstract partial class : BaseController { /// <summary> /// Return a list of all instances of for use in menus, etc; /// </summary> protected IList<> ( ISession hibernator) { return hibernator.CreateCriteria(typeof()) .AddOrder( ) .SetCacheable( true) .SetCacheRegion( "") .List<>(); } } } /* * Not generating controller for entity , * as it has no forms, pages or lists. */ /* ---- [ cut here: next file 'Controller.auto.cs'] ---------------- */ //------------------------------------------------------------------ // // // Controller.auto.cs // // (c) 2007 Cygnet Solutions Ltd // // Controller for auto-generated forms for editing s // Automatically generated from application description using // adl2controllerclasses.xslt 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.Exceptions; using Cygnet.Web.Helpers; using Cygnet.Web.Controllers; using Cygnet.Web.SmartControls; using NHibernate; using NHibernate.Expression; using Castle.MonoRail.Framework; using Iesi.Collections.Generic; using ; 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> [ Layout(""), Rescue(""), ControllerDetails("", Area = ""), Helper(typeof(StylesHelper), "StylesHelper"), Helper(typeof(), "") ] public partial class : { /* The SmartFormHelper stuff in generated controller classes does not yet work. There is some * hope that in future it will offer definite benefits and in the mean time it is doing no harm. * However if you are looking for bugs look elsewhere - this is not currently used */ protected class : SmartFormHelper { public () { /* Entity is foreign..? */ Register<>( "", new TypeMenuControl<>( "","")); Register<>( "", EntityMenuControl<>.Instance); Register<>( "", EntityShuffleControl<>.Instance); } } /// <summary> /// Temporary hack to sort a problem with uninitialised messages /// </summary> public void fixupMessages() { ISession hibernator = NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], Session[NHibernateHelper.PASSTOKEN] ); ICollection<> instances = hibernator.CreateCriteria( typeof( )) .List<>(); foreach ( instance in instances) { if ( == null || == 0 ){ = new Message(); hibernator.Save( ); } hibernator.Save( instance); } hibernator.Flush(); list(); } /// <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>(); /* A 'newborn' instance can be updated even if the current user doesn't have * update permissions, seeing that we use an update operation to set the * field values and save the entity. */ Boolean isnewborn = false; /* the instance (record) of type we're dealing with */ record = null; try { /* a criteria object to use in distinctness checks */ ICriteria matchCriteria = null; record = FetchRecord( hibernator); if ( HasNoErrors()) { if ( record == null) { /* it seems to be new, create persistent object - if the user is permitted to */ AssertUserCanCreate(); try { if ( AllKeys()) { record = new ( Int32.Parse( Form[""]) hibernator.CreateCriteria( typeof( )) Form[ ""] .UniqueResult<>() Form[""] , ); } else { record = new (); } } catch ( FormatException) { /* failed to parse a number - not wholly unexpected, since it's most likely * that an empty string was passed in */ record = new (); } catch ( NullReferenceException) { /* again, probably more normal than otherwise */ record = new (); } messages.Add( "New record created"); isnewborn = true; } if ( record != null) { /* a transaction to ensure our database operations are atomic */ ITransaction tx = null; if ( ! isnewborn) { /* isnewborn cannot be true unless we've already checked user can create * so no need to do it again here */ AssertUserCanUpdate(); } try { /* begin our atomic transaction */ tx = hibernator.BeginTransaction(); /* actually update the record */ BindObjectInstance( record, ParamStore.Form, "instance"); /* there is at least one slot whose value is an internationalised message; * if these have yet to be initialised they must be handled specially */ Locale locale = GetBestLocaleForUser(); if ( ! String.IsNullOrEmpty( Form[""])){ /* there's an uninitialised message for this slot */ Message mess = record.; if ( mess == null) { mess = new Message(); } hibernator.Save( mess); Translation trans = mess.GetTranslationObject( locale, hibernator); if ( trans == null) { trans = new Translation( mess, locale); } trans.MessageText = Form[""]; record. = mess; hibernator.Save( trans); } /* 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. */ if ( ! String.IsNullOrEmpty( Form[""])) { record. = Form[ ""] ; } ADL: ERROR: Could not fix up value of , because no entity was found called /* 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( ""); /* update the linking table for my ; first smash the old values */ if ( != null) { .Clear(); } else { = new HashedSet<>(); } if ( != null) { /* then reinstate the values from the indexes passed */ foreach ( string index in ) { .Add( hibernator.CreateCriteria(typeof()) .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.KeyString; bool found = false; foreach ( string index in ) { if ( index.Equals( itemId)) { found = true; break; } } /* foreach ( string index... */ if ( ! found) { record..Remove( item); break; } } /* foreach ( item ... */ /* then add any on the included list which are not already members */ foreach ( string index in ) { item = hibernator.CreateCriteria(typeof()) .UniqueResult<>(); if ( ! record..Contains( item)) { /* check whether it's already a child of another * and, if it is, remove it */ oldparent = ; if ( oldparent != null) { oldparent..Remove( item); hibernator.Save( oldparent); } /* then add it to my */ record..Add( item); = record; hibernator.Save( item); } } /* foreach ( string index... */ } /* if ( Form.GetValues( "") != null) */ /* write the record to the database, in order to guarantee we have a valid key */ hibernator.Save(record); hibernator.Flush(); tx.Commit(); messages.Add( ""); } /* try actually commit */ catch ( Exception any) { tx.Rollback(); messages.Add( ""); throw any; } } /* if ( record != null) */ else { throw new ApplicationException( String.Format( " ")); } } /* if ( HasNoErrors()) */ } /* try */ catch ( DataSuitabilityException dse) { AddError( dse); } catch ( ApplicationException axe) { AddError( axe.Message); } if ( ! HasNoErrors()) { /* the session may be polluted; create a new session */ NHibernateHelper.CloseSession(); hibernator = NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], Session[NHibernateHelper.PASSTOKEN] ); record = FetchRecord( hibernator); } /* if ( ! HasNoErrors()) */ ( record); } /// <summary> /// Actually delete the selected record /// </summary> [AccessibleThrough(Verb.Post)] public void Delete() { AssertUserCanDelete(); ISession hibernator = NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], Session[NHibernateHelper.PASSTOKEN] ); if ( "true".Equals( Params["reallydelete"])) { record = FetchRecord( hibernator); if ( record != null) { hibernator.Delete( record); hibernator.Flush(); } else { throw new ApplicationException( "No such record?"); } } Redirect( ""); 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) { AssertUserCanRead(); ISession hibernator = NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], Session[NHibernateHelper.PASSTOKEN] ); ICriteria search = hibernator.CreateCriteria(typeof()); if ( ! String.IsNullOrEmpty( Params[ ""])) { search Params[""] ; } search.AddOrder(); IList<> instances = search.List<>(); PropertyBag["username"] = Session[ NHibernateHelper.USERTOKEN]; PropertyBag["instances"] = PaginationHelper.CreatePagination( this, instances, 25); RenderViewWithFailover(view + ".vm", view + ".auto.vm"); } /// <summary> /// Check whether values for all my keys are available in the form fields /// </summary> protected bool AllKeys() { /* whether we have valid values for all the key fields */ bool result = true; if ( String.IsNullOrEmpty( Form[""])) { result = false; } else if ( "".Equals( Form[""])) { /* nasty artefact of NVelocity forms - default 'null value' is dollar followed by fieldname */ result = false; } return result; } /// <summary> /// Fetch the record represented by the values in the current Form /// </summary> protected FetchRecord(ISession hibernator) { /* the instance (record) of type we're dealing with */ record = null; if ( AllKeys()){ /* it's (probably) existing, retrieve it */ record = hibernator.CreateCriteria(typeof()) Form[""] .UniqueResult<>(); } return record; } } } /* ---- [ cut here: next file 'junk'] ------------------------- */ if ( String.IsNullOrEmpty( Form[ "" ])) { AddError( " " ); } "" /// <summary> /// Handle the submission of the form named /// </summary> [AccessibleThrough(Verb.Post)] public void ( ) { string command = Form[ "command"]; if ( command == null) { throw new Exception( ""); } 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] ); record = FetchRecord( hibernator); TypedPropertyBag = new { username = Session[ NHibernateHelper.USERTOKEN], instance = record }; RenderViewWithFailover( "maybedelete.vm", "maybedelete.auto.vm"); } else if ( command.Equals( "store")) { Store(); } else { throw new Exception( String.Format(" ", command)); } } /// <summary> /// Show the form named , with no existing record /// </summary> [AccessibleThrough(Verb.Get)] public void ( ) { AssertUserCanRead(); record = null; ( record); } /// <summary> /// Show the form named , for a new record, but with the /// value for already predetermined /// </summary> [AccessibleThrough(Verb.Get)] public void ( string ) { AssertUserCanRead(); ISession hibernator = NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], Session[NHibernateHelper.PASSTOKEN] ); record = new (); record. = ; ( record); } /// <summary> /// Show the form named , containing the indicated record. As /// the primary key of the record is itself an entity, we need to first fetch that entity /// </summary> /// <param name="">the key value of the key value of the record to show</param> /// <param name="">the key value of the record to show</param> [AccessibleThrough(Verb.Get)] public void ( string , ) { ISession hibernator = NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], Session[NHibernateHelper.PASSTOKEN] ); ( hibernator.CreateCriteria( typeof()) .UniqueResult<>()); } /// <summary> /// Show the form named , containing the indicated record /// </summary> /// <param name="record">the record to show</param> protected void ( record) { ISession hibernator = NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], Session[NHibernateHelper.PASSTOKEN] ); if ( record == null ){ record = new (); BindObjectInstance( record, ParamStore.Form, "instance"); } TypedPropertyBag = new { username = Session[ NHibernateHelper.USERTOKEN], 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( ""); } /* */ /* should be distinct: check that it is */ matchCriteria = hibernator.CreateCriteria(typeof()); matchCriteria Form[""] ; if ( record != null) { /* i.e. we do have values for each of our key fields... */ matchCriteria.Add(Expression.Not( Form[""] )); } if ( matchCriteria.List<>().Count > 0) { AddError( String.Format("There is already a {0} with the {1} '{2}'", "", "", Form[""])); } /* form menus */ /* produce a list of to populate the select for */ /* produce a list of to populate the LHS of the shuffle for */ /* produce a list of to populate the multi-select for */ /* there's no way I can find of producing a set of just those entities * we'll need menus for. So we set up variables for all the menus we might * need, and then only instantiate those we do need. */ /* produce a list of to populate the LHS of the shuffle for */ /* produce a list of to populate the multi-select for */ = ( NHibernateHelper.GetCurrentSession()), ADL: ERROR: No entity passed to template primary-key-csharp-type ADL: WARNING: entity '' has no primary key. You will have to manually edit ADL: ERROR: No key for entity: ADL: WARNING: Entity has a composite primary key. You will need to manually edit ADL: WARNING: Entity has no primary key. You will need to manually edit .Add( ) .Add( ) Expression.Eq("", Int32.Parse( ) Decimal.Parse( ) DateTime.Parse( ) ADL: Error: properties of type cannot yet be used in equality tests ) Expression.Like( "", "%"++"%") /* match to four significant places */ Expression.Between( "", Double.Parse( ) * 1.0001, Double.Parse( ) * 0.9999) true true true true true true false ADL: ERROR: property passed to fetch-property-instance whose type is not 'entity' hibernator.CreateCriteria(typeof()) .UniqueResult<>()