/// <summary> /// Creates a new sub entity and assigns the parent entity specified in the query strings. /// </summary> /// <returns></returns> public override IEntity Create() { IEntity entity = null; using (LogGroup logGroup = LogGroup.Start("Preparing the form to create a new sub entity.", NLog.LogLevel.Debug)) { if (EnsureAuthorised()) { Guid parentID = Guid.Empty; string parentUniqueKey = String.Empty; if (QueryStrings.Available) { parentID = QueryStrings.GetID("Parent"); parentUniqueKey = QueryStrings.GetUniqueKey("Parent"); } else { throw new InvalidOperationException("Query strings aren't available. Provide parent ID or parent unique key manually."); } LogWriter.Debug("Parent ID: " + parentID); LogWriter.Debug("Parent unique key: " + parentUniqueKey); entity = Create(parentID, parentUniqueKey); } } return(entity); }
/// <summary> /// Displays the page for viewing an entity. /// </summary> public virtual void View <T>() where T : IEntity { Guid id = QueryStrings.GetID(Command.TypeName); string uniqueKey = QueryStrings.GetUniqueKey(Command.TypeName); if (id != Guid.Empty) { View <T>(id); } else if (uniqueKey != String.Empty) { View <T>(uniqueKey); } else { throw new InvalidOperationException("Cannot view entity. No identifier found."); } }
/// <summary> /// Loads the entity specified by the query string and prepares it for viewing. /// </summary> /// <returns>The entity specified by the query string.</returns> public virtual T PrepareView <T>() where T : IEntity { Guid goalID = QueryStrings.GetID(Command.TypeName); string goalKey = QueryStrings.GetUniqueKey(Command.TypeName); if (goalID != Guid.Empty) { return((T)LoadEntity <T>(goalID)); } else if (goalKey != String.Empty) { return((T)LoadEntity <T>(goalKey)); } else { throw new InvalidOperationException("Cannot find entity ID or unique key in query string."); } }
/// <summary> /// Loads the entity specified by the query string. /// </summary> /// <returns></returns> public virtual T Load <T>() where T : IEntity { T entity = default(T); using (LogGroup logGroup = LogGroup.Start("Loading the entity specified in the query string.", NLog.LogLevel.Debug)) { Guid id = QueryStrings.GetID(typeof(T).Name); string uniqueKey = QueryStrings.GetUniqueKey(typeof(T).Name); LogWriter.Debug("Entity ID: " + id.ToString()); LogWriter.Debug("Unique key: " + uniqueKey); if (id != Guid.Empty) { entity = Retriever.Retrieve <T>(id); } else if (uniqueKey != String.Empty) { entity = Retriever.Retrieve <T>(uniqueKey); } else { throw new Exception("No ID or unique key found in the URL."); } if (entity == null) { LogWriter.Debug("Entity: [null]"); } else { LogWriter.Debug("Entity: " + entity.GetType().FullName); } } return(entity); }
/// <summary> /// Retrieves the ID of the entity being edited. /// </summary> /// <returns></returns> public virtual Guid GetID() { return(QueryStrings.GetID(Command.TypeName)); }