internal bool Execute(
            bool skipIfNoChanges, bool formValuesChanged, Action<EwfValidation, IEnumerable<string>> validationErrorHandler, bool performValidationOnly = false,
            Tuple<Action, Action> actionMethodAndPostModificationMethod = null)
        {
            var validationNeeded = validations.Any() && ( !skipIfNoChanges || formValuesChanged );
            if( validationNeeded ) {
                var topValidator = new Validator();
                foreach( var validation in validations ) {
                    if( topValidations.Contains( validation ) )
                        validation.Method( AppRequestState.Instance.EwfPageRequestState.PostBackValues, topValidator );
                    else {
                        var validator = new Validator();
                        validation.Method( AppRequestState.Instance.EwfPageRequestState.PostBackValues, validator );
                        if( validator.ErrorsOccurred )
                            topValidator.NoteError();
                        validationErrorHandler( validation, validator.ErrorMessages );
                    }
                }
                if( topValidator.ErrorsOccurred )
                    throw new DataModificationException( Translation.PleaseCorrectTheErrorsShownBelow.ToSingleElementArray().Concat( topValidator.ErrorMessages ).ToArray() );
            }

            var skipModification = !modificationMethods.Any() || ( skipIfNoChanges && !formValuesChanged );
            if( performValidationOnly || ( skipModification && actionMethodAndPostModificationMethod == null ) )
                return validationNeeded;

            DataAccessState.Current.DisableCache();
            try {
                if( !skipModification ) {
                    foreach( var method in modificationMethods )
                        method();
                }
                if( actionMethodAndPostModificationMethod != null )
                    actionMethodAndPostModificationMethod.Item1();
                DataAccessState.Current.ResetCache();
                AppRequestState.Instance.PreExecuteCommitTimeValidationMethodsForAllOpenConnections();
                if( actionMethodAndPostModificationMethod != null )
                    actionMethodAndPostModificationMethod.Item2();
            }
            catch {
                AppRequestState.Instance.RollbackDatabaseTransactions();
                DataAccessState.Current.ResetCache();
                throw;
            }

            return true;
        }
Example #2
0
 private Action ap_cmb(Tuple<Action, Action> code)
 {
     return delegate() { code.Item1(); code.Item2(); };
 }