예제 #1
0
        protected IActionResult Form <TForm>(TForm form, Func <IActionResult> success, Func <IActionResult> failure)
            where TForm : IForm
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _formHandlerFactory.Create <TForm>().Execute(form);

                    return(success());
                }
                catch (FormException e)
                {
                    ModelState.AddModelError(string.Empty, e.Message);
                }
            }

            return(failure());
        }
        protected ActionResult Form <TForm>(TForm form, Func <ActionResult> successResult, Func <ActionResult> failResult) where TForm : IForm
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _formHandlerFactory.Create <TForm>().Execute(form);

                    return(successResult());
                }
                catch (FormHandlerException fhe)
                {
                    var key = string.IsNullOrEmpty(fhe.Key) ? "form" : fhe.Key;
                    ModelState.AddModelError(key, fhe.Message);
                }
            }

            TempData[ModelStateKey] = ModelState;
            return(failResult());
        }