src/MVCContrib/FluentController/AbstractFluentController.cs
/// <summary>
/// Wrap controller calls with this method.  This will check for ModelState.IsValid
/// before performing <paramref name="action"/> and check for ModelState.IsValid afterwards.
/// <typeparam name="T">The type of the model returned from this method.  This will be passed into the Valid method.</typeparam>
/// <param name="action">The action to perform.</param>
/// <param name="executeActionWhenInvalid">If true, will execute the action even if ModelState.IsValid is false initially</param>
/// </summary>
/// <returns>A FluentControllerAction that can be used to setup the valid and invalid actions.</returns>
Wrap controller calls with this method.
Wrap controller calls with this method .
public virtual FluentControllerAction<T> CheckValidCall<T>(Func<T> action, bool executeActionWhenInvalid)
		{
			T model = default(T);
			int numErrors = ModelState.Values.ReadValue(v => v.Select(x => x.Errors.Count).Sum());
			if(action != null)
			{
				if(executeActionWhenInvalid || ModelState.IsValid)
				{
					var obj = ExecuteCheckValidCall(() => action());
					if(obj != null)
					{
						model = (T)obj;
					}
				}
			}
			int newErrors = ModelState.Values.Select(x => x.Errors.Count).Sum() - numErrors;
			return new FluentControllerAction<T>(ModelState.IsValid, model, newErrors, this);
		}
public virtual FluentControllerAction < T > CheckValidCall < T > ( Func < T > action , bool executeActionWhenInvalid ) { T model = default ( T ) ; int numErrors = ModelState . Values . ReadValue ( v => v . Select ( x => x . Errors . Count ) . Sum ( ) ) ; if ( action != null ) { if ( executeActionWhenInvalid || ModelState . IsValid ) { var obj = ExecuteCheckValidCall ( ( ) => action ( ) ) ; if ( obj != null ) { model = ( T ) obj ; } } } int newErrors = ModelState . Values . Select ( x => x . Errors . Count ) . Sum ( ) - numErrors ; return new FluentControllerAction < T > ( ModelState . IsValid , model , newErrors , this ) ; }
Wrap controller calls with this method.
Wrap controller calls with this method .
A FluentControllerAction that can be used to setup the valid and invalid actions.
A FluentControllerAction that can be used to setup the valid and invalid actions .
action
Func<T>
executeActionWhenInvalid
bool