/// <summary> /// Ensures that the user is authorised to create an entity of the specified type. /// </summary> /// <returns>A value indicating whether the user is authorised.</returns> public override bool EnsureAuthorised() { bool isAuthorised = AuthoriseSaveStrategy.New(Command.TypeName).IsAuthorised(Command.TypeName); if (!isAuthorised) { FailAuthorisation(); } return(isAuthorised); }
/// <summary> /// Saves the provided entity. /// </summary> /// <param name="entity">The entity to save.</param> /// <returns>A value indicating whether the entity was valid and was therefore saved.</returns> public virtual bool Save(IEntity entity) { bool saved = false; using (LogGroup logGroup = LogGroup.StartDebug("Saving the provided entity.")) { if (entity == null) { throw new ArgumentNullException("entity"); } LogWriter.Debug("Entity type: " + entity.GetType().FullName); if (RequireAuthorisation) { LogWriter.Debug("Authorisation required."); AuthoriseSaveStrategy.New(entity.ShortTypeName).EnsureAuthorised(entity); } else { LogWriter.Debug("Authorisation NOT required. Skipping authorisation check."); } CheckStrategies(entity); if (entity.IsValid) { LogWriter.Debug("Is valid."); DataAccess.Data.Saver.Save(entity); saved = true; // [Important] Trigger the reactions React(entity); } else { LogWriter.Debug("Is not valid."); saved = false; } LogWriter.Debug("Saved: " + saved.ToString()); } return(saved); }