/* ---- [ 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 System.Data.SqlClient; using NHibernate; using NHibernate.Expression; using Cygnet.DBAuth; 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(FormatterHelper), "t"), Helper(typeof(SecurityHelper), "SecurityHelper") ] public abstract partial class : BaseController { /* authentication layer is requested to be 'database', but in fact database-layer authentication does not work well with NHibernate so this is being ignored. */ ADL: ERROR: invalid value () provided for authentication-layer /// <summary> /// Return a list of all instances of for use in menus, etc; /// </summary> protected IList<> ( ) { IList<> result = new List<>(); if ( InGroup( "")|| ){ result = GetDBSession().CreateCriteria(typeof()) .AddOrder( ) .SetCacheable( true) .SetCacheRegion( "") .List<>(); } return result; } } } /* * 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.Entities; using Cygnet.Exceptions; using Cygnet.Web.Helpers; using Cygnet.Web.Controllers; using Cygnet.Web.SmartControls; using Cygnet.Utility; 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 : { 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 = GetDBSession(); ICollection<> instances = hibernator.CreateCriteria( typeof( )) .List<>(); foreach ( instance in instances) { if ( == null || == 0 ){ = new Message(); .BeforeUpdateHook( hibernator); hibernator.SaveOrUpdate( ); .AfterUpdateHook( hibernator); } instance.BeforeUpdateHook( hibernator); hibernator.SaveOrUpdate( instance); instance.AfterUpdateHook( hibernator); } 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 = GetDBSession(); List<string> messages = new List<string>(); PropertyBag["messages"] = messages; /* 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(); /* list of entities modified in this transaction */ List<Entity> modified = new List<Entity>(); /* actually update the record */ BindObjectInstance( record, ParamStore.Form, "instance"); modified.Add( record); /* 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(); } mess.BeforeUpdateHook( hibernator); hibernator.SaveOrUpdate( mess); mess.AfterUpdateHook( hibernator); Translation trans = mess.GetTranslationObject( locale, hibernator); if ( trans == null) { trans = new Translation( mess, locale); } trans.MessageText = Form[""]; record. = mess; trans.BeforeUpdateHook( hibernator); hibernator.SaveOrUpdate( trans); trans.AfterUpdateHook( hibernator); } /* 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[""]) && ! EntityMenuControl<>.NULLMARKER.Equals ( Form[""])) { record. = Form[ ""] ; modified.Add( record.); } ADL: ERROR: Could not fix up value of , because no entity was found called /* For a link, collect changes to link table and process them */ if ( InGroup( "") || false) { /* however, we cannot do anything unless we have delete permissions on the table, so * should not try. */ LinkChanges<> changes = LinkTableUpdater<>.Changes( , Form.GetValues( ""), hibernator); foreach ( var item in changes.ToRemove) { modified.Add(item); .Remove(item); .Remove( record); /* WARNING WARNING WARNING! Could not uniquely determine the far side property; * redesign your application or manually maintain this code! */ WARNING: Could not uniquely determine far end of link represented by property of } foreach ( var item in changes.ToAdd) { modified.Add(item); .Add(item); .Add( record); /* WARNING WARNING WARNING! Could not uniquely determine the far side property; * redesign your application or manually maintain this code! */ WARNING: Could not uniquely determine far end of link represented by property of } } /* if ( InGroup( "") || false) */ /* 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 ( InGroup( "") || false) { /* but once again only if we can delete and create entities at the far end. */ 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); modified.Add( 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); modified.Add( oldparent); } /* then add it to my */ record..Add( item); = record; modified.Add( item); } } /* foreach ( string index... */ } /* if ( Form.GetValues( "") != null) */ } /* if ( InGroup( "") || false) */ /* write the modified records to the database */ foreach ( Entity item in modified) { item.BeforeUpdateHook( hibernator); hibernator.SaveOrUpdate(item); item.AfterUpdateHook( hibernator); } /* and if no exceptions, commit */ tx.Commit(); messages.Add( ""); } /* try actually commit */ catch ( Exception any) { messages.Add( ""); AddError( any); try { tx.Rollback(); } catch ( ObjectDisposedException ode) { AddError( ode); } } /* catch ( Exception 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 */ CloseDBSession(); hibernator = GetDBSession(); record = FetchRecord( hibernator); } /* if ( ! HasNoErrors()) */ ( record); } /// <summary> /// Actually delete the selected record /// </summary> [AccessibleThrough(Verb.Post)] public void Delete() { AssertUserCanDelete(); ISession hibernator = GetDBSession(); if ( "true".Equals( Params["reallydelete"])) { record = FetchRecord( hibernator); if ( record != null) { record.BeforeDeleteHook( hibernator); 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 = GetDBSession(); ICriteria search = hibernator.CreateCriteria(typeof()); if ( ! String.IsNullOrEmpty( Params[ ""])) { search Params[""] ; } search.AddOrder(); IList<> instances = search.List<>(); PropertyBag["instances"] = PaginationHelper.CreatePagination( this, instances, ); 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 ( (record == null || == null) && 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 = GetDBSession(); record = FetchRecord( hibernator); TypedPropertyBag = new { 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 = new (); ISession hibernator = GetDBSession(); TypedPropertyBag = new { instance = record }; RenderViewWithFailover("", ""); } /// <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 = GetDBSession(); 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 = GetDBSession(); ( 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 = GetDBSession(); TypedPropertyBag = new { 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 */ = ( ), 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<>()