Exemplo n.º 1
0
        public PartialViewResult Execute(CalculationViewModel model)
        {
            if (ModelState.IsValid)
            {
                bool status = ExecuteActionWithValidation(() =>
                {
                    var calculation = GetCalculationFromViewModel(model);

                    var calculationService = new CalculationService();
                    calculationService.Execute(calculation);

                    // Rebind View
                    model = GetViewModelFromCalculation(calculationService.GetViewById(calculation.Id));

                    SetSuccessMessage("The calculation is enqueued.");
                });

                if (status)
                {
                    // Clear ModelState otherwise Id will stay 0
                    ModelState.Clear();
                    return(PartialView("Form", model));
                }
            }

            return(PartialView("Form"));
        }