コード例 #1
0
        //
        // Private
        //
        private async Task <IActionResult> ProcessPost(Guid id, AmendDirectDebitVm amendDirectDebitVmPostedBack)
        {
            if (!ModelState.IsValid)
            {
                if (amendDirectDebitVmPostedBack.SelectedPlanSetupOption == PlanSetupOptions.AverageSetupValue ||
                    amendDirectDebitVmPostedBack.SelectedPlanSetupOption == PlanSetupOptions.DisposableIncome)
                {
                    if (amendDirectDebitVmPostedBack.DirectDebitAmount >
                        amendDirectDebitVmPostedBack.OutstandingBalance)
                    {
                        ModelState.Clear();
                        var initialVm = DeserialiseModel <AmendDirectDebitVm>(amendDirectDebitVmPostedBack.InitialState);
                        amendDirectDebitVmPostedBack.DirectDebitAmount = initialVm.DirectDebitAmount;
                        ModelState.AddModelError(nameof(AmendDirectDebitVm.SelectedPlanSetupOption),
                                                 $"{ValidationMessages.AmountGreaterThenAllowed}{amendDirectDebitVmPostedBack.OutstandingBalance}");
                    }
                }

                Debug.Assert(amendDirectDebitVmPostedBack.InitialState != null,
                             "Initial state must be stashed to re-create view on round-trip");
                return(View(amendDirectDebitVmPostedBack));
            }

            _gtmService.RaiseAmendDirectDebitEvent_DetailsSelected(amendDirectDebitVmPostedBack, LoggedInUserId);
            ApplicationSessionState.LogSetUpPlanResult = true;

            var totalMonths = _amendDirectDebitPlanService.CalculateTermInMonths(
                amendDirectDebitVmPostedBack.DerivedBalance, amendDirectDebitVmPostedBack.DirectDebitAmount.Value,
                amendDirectDebitVmPostedBack.PlanFrequency);
            var years  = totalMonths / 12;
            var months = totalMonths % 12;

            var amendDirectDebitConfirmVm = new AmendDirectDebitConfirmVm
            {
                // Stash filled in form, as other fields will not be in inputs on confirm page
                FilledInState = SerialiseModel(amendDirectDebitVmPostedBack),

                LowellReference             = amendDirectDebitVmPostedBack.LowellReference,
                ClientName                  = amendDirectDebitVmPostedBack.ClientName,
                OutstandingBalance          = amendDirectDebitVmPostedBack.OutstandingBalance,
                RegularAccountPaymentAmount = amendDirectDebitVmPostedBack.DirectDebitAmount.Value,
                PlanFrequency               = amendDirectDebitVmPostedBack.PlanFrequency,
                PlanStartDate               = amendDirectDebitVmPostedBack.PlanStartDate,
                TermYears  = years,
                TermMonths = months
            };

            return(View("Confirm", amendDirectDebitConfirmVm));
        }