Esempio n. 1
0
        /// <summary>
        /// Deletes the provided entity.
        /// </summary>
        /// <param name="entity"></param>
        public virtual void ExecuteDelete(IEntity entity)
        {
            using (LogGroup logGroup = LogGroup.Start("Deleting the provided entity.", NLog.LogLevel.Debug))
            {
                if (entity == null)
                {
                    throw new ArgumentNullException("entity");
                }

                if (EnsureAuthorised(entity))
                {
                    if (entity == null)
                    {
                        LogWriter.Debug("Entity: [null]");
                    }
                    else
                    {
                        LogWriter.Debug("Entity: " + entity.GetType().FullName);
                    }

                    Deleter.Delete(entity);

                    LogWriter.Debug("Done");

                    // Display the result
                    Result.Display(DynamicLanguage.GetEntityText("EntityDeleted", entity.ShortTypeName));

                    NavigateAfterDelete(entity);
                }
            }
        }
        /// <summary>
        /// Updates the provided entity back to the data store.
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>A bool value indicating the success of the update. If it fails it's due to the entity being invalid.</returns>
        public virtual bool ExecuteUpdate(IEntity entity)
        {
            bool didSucceed = false;

            using (LogGroup logGroup = LogGroup.Start("Updating the provided entity.", NLog.LogLevel.Debug))
            {
                if (EnsureAuthorised())
                {
                    DataSource = entity;

                    if (entity == null)
                    {
                        throw new ArgumentNullException("entity");
                    }

                    // Update the entity
                    if (Updater.Update(entity))
                    {
                        Result.Display(DynamicLanguage.GetEntityText(EntityUpdatedLanguageKey, Command.TypeName));

                        didSucceed = true;
                    }
                    else
                    {
                        // Add the validation error to the result control
                        Validation.DisplayError(entity);

                        didSucceed = false;
                    }
                }

                LogWriter.Debug("Did succeed: " + didSucceed.ToString());
            }
            return(didSucceed);
        }
Esempio n. 3
0
        /// <summary>
        /// Saves the provided entity.
        /// </summary>
        /// <param name="entity">The entity to save.</param>
        /// <returns>A value indicating whether the entity was saved. If it fails it's due to the entity being invalid.</returns>
        public virtual bool ExecuteSave(IEntity entity)
        {
            bool saved = false;

            using (LogGroup logGroup = LogGroup.StartDebug("Saving data from form."))
            {
                if (EnsureAuthorised(entity))
                {
                    DataSource = entity;

                    // Save the entity
                    if (Saver.Save(entity))
                    {
                        // Display the result
                        Result.Display(DynamicLanguage.GetEntityText(EntitySavedLanguageKey, Command.TypeName));

                        saved = true;
                    }
                    else
                    {
                        // Add the validation error to the result control
                        Validation.DisplayError(entity);

                        saved = false;
                    }
                }
                LogWriter.Debug("Saved: " + saved.ToString());
            }
            return(saved);
        }
        /// <summary>
        /// Starts the edit process for the entity provided.
        /// </summary>
        /// <returns>The entity provided.</returns>
        public virtual IEntity ExecuteEdit(IEntity entity)
        {
            using (LogGroup logGroup = LogGroup.Start("Editing the provided entity.", NLog.LogLevel.Debug))
            {
                Validation.CheckMessages(entity);

                if (EnsureAuthorised(entity))
                {
                    StartEdit();

                    Container.WindowTitle = DynamicLanguage.GetEntityText("EditEntity", Command.TypeName);

                    Load(entity);
                }
            }
            return(entity);
        }