public virtual async Task <ActionResult> Push() { var parameter = dispatcher.Query(new GetMvdParameterQuery() { Params = ControllerContext.GetNameValueCollection() }); var commands = await new CreateMessageByType2.AsCommands { Provider = _serviceProvider, IncTypes = parameter.Type, Controller = this, IsComposite = parameter.IsCompositeArray }.Execute(); var composite = new CommandComposite(commands); return(await TryPushAsync(async commandComposite => await dispatcher.QueryAsync(new MVDExecuteAsync() { Instance = composite }), composite, setting => setting.SuccessResult = () => { var data = commands.Length == 1 ? commands[0].Result : commands.Select(r => r.Result); return IncodingResult.Success(data); })); }
public virtual async Task <ActionResult> Validate() { var parameter = dispatcher.Query(new GetMvdParameterQuery() { Params = ControllerContext.GetNameValueCollection() }); // ReSharper disable once UnusedVariable var instance = await new CreateMessageByType2() { Type = parameter.Type, Controller = this }.Execute(); return(ModelState.IsValid ? IncodingResult.Success() : IncodingResult.Error(ModelState)); }
protected async Task <ActionResult> TryPushAsync(Func <CommandComposite, Task> push, CommandComposite composite, Action <IncTryPushSetting> action = null, bool?isAjax = null) { var setting = new IncTryPushSetting(); action.Do(r => r(setting)); Func <ActionResult> defaultSuccess = () => View(composite.Parts[0]); var isActualAjax = isAjax.GetValueOrDefault(HttpContext.Request.IsAjaxRequest()); if (isActualAjax) { defaultSuccess = () => IncodingResult.Success(); } var success = setting.SuccessResult ?? defaultSuccess; Func <IncWebException, ActionResult> defaultError = (ex) => View(composite.Parts[0]); if (isActualAjax) { defaultError = (ex) => IncodingResult.Error((ModelStateDictionary)ModelState); } var error = setting.ErrorResult ?? defaultError; if (!ModelState.IsValid) { return(error(IncWebException.For(string.Empty, string.Empty))); } try { await push(composite); return(success()); } catch (IncWebException exception) { foreach (var pairError in exception.Errors) { foreach (var errorMessage in pairError.Value) { ModelState.AddModelError(pairError.Key, errorMessage); } } return(error(exception)); } }
public virtual async Task <ActionResult> Query() { var parameter = dispatcher.Query(new GetMvdParameterQuery() { Params = ControllerContext.GetNameValueCollection() }); var query = await new CreateMessageByType2() { Type = parameter.Type, Controller = this }.Execute(); if (parameter.IsValidate && !ModelState.IsValid) { return(IncodingResult.Error(ModelState)); } var composite = new CommandComposite((IMessage)query); return(await TryPushAsync(async commandComposite => await dispatcher.QueryAsync(new MVDExecuteAsync() { Instance = composite }), composite, setting => setting.SuccessResult = () => IncodingResult.Success(composite.Parts[0].Result), isAjax : true)); }
public IIncodingMetaLanguageEventBuilderDsl Direct(object result) { return(Direct(IncodingResult.Success(result))); }
protected async Task <IncodingResult> IncPartialView([AspMvcView] string viewName, object model = null) { return(IncodingResult.Success(await RenderToString(viewName, model))); }
protected IncodingResult IncJson(object model) { return(IncodingResult.Success(model)); }