public static async Task <ActionResult> Helper( ModelStateDictionary ModelState, ActionResult returnAction) { if (!ModelState.IsValid) { return(new ViewResult(command)); } var result = await mediator.ProcessCommandAsync(command); if (!result.IsSuccess()) { ModelState.AddErrorsToModelState(result); return(new ViewResult(command)); } return(returnAction); }
// You may need to constrain this to where T : class, didn't test it public static async Task <ActionResult> Helper <T>(T command, ModelStateDictionary ModelState, IMediator mediator, ActionResult returnAction, ActionResult successAction, ActionResult failureAction) { if (!ModelState.IsValid) { return(failureResult); } var result = await mediator.ProcessCommandAsync(command); if (!result.IsSuccess()) { ModelState.AddErrorsToModelState(result); return(successResult); } return(returnAction); }