コード例 #1
0
 protected IncodingResult IncPartialView([AspMvcView] string viewName, object model = null)
 {
     Guard.NotNullOrWhiteSpace("viewName", viewName);
     ViewData.Model = model;
     using (var sw = new StringWriter())
     {
         var viewResult  = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
         var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
         viewResult.View.Render(viewContext, sw);
         return(IncodingResult.Success(sw.GetStringBuilder().ToString()));
     }
 }
コード例 #2
0
        protected ActionResult TryPush(Action <CommandComposite> 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(ModelState);
            }
            var error = setting.ErrorResult ?? defaultError;

            if (!ModelState.IsValid)
            {
                return(error(IncWebException.For(string.Empty, string.Empty)));
            }

            try
            {
                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));
            }
        }
コード例 #3
0
        protected ActionResult TryPush(CommandComposite composite, Action <IncTryPushSetting> action = null)
        {
            var setting = new IncTryPushSetting();

            action.Do(r => r(setting));

            Func <ActionResult> defaultSuccess = () => View(composite.Parts[0].Message);

            if (HttpContext.Request.IsAjaxRequest())
            {
                defaultSuccess = () => IncodingResult.Success();
            }
            var success = setting.SuccessResult ?? defaultSuccess;

            Func <IncWebException, ActionResult> defaultError = (ex) => View(composite.Parts[0].Message);

            if (HttpContext.Request.IsAjaxRequest())
            {
                defaultError = (ex) => IncodingResult.Error(ModelState);
            }
            var error = setting.ErrorResult ?? defaultError;

            if (!ModelState.IsValid)
            {
                return(error(IncWebException.Empty));
            }

            try
            {
                this.dispatcher.Push(composite);
                return(success());
            }
            catch (IncWebException exception)
            {
                ModelState.AddModelError(exception.Property, exception.Message);
                return(error(exception));
            }
        }
コード例 #4
0
 protected IncodingResult IncJson(object model)
 {
     return(IncodingResult.Success(model));
 }
 public IIncodingMetaLanguageEventBuilderDsl Direct(object result)
 {
     return(Direct(IncodingResult.Success(result)));
 }
コード例 #6
0
 protected IncodingResult IncPartialView([AspMvcView] string viewName, object model = null)
 {
     return(IncodingResult.Success(RenderToString(viewName, model)));
 }