Beispiel #1
0
        private async Task <IActionResult> ProcessDirectDebitDetailsPost(Guid lowellReferenceSurrogateKey,
                                                                         DirectDebitDetailsVm directDebitDetailsVmWithUserEntries)
        {
            if (!ModelState.IsValid)
            {
                Debug.Assert(directDebitDetailsVmWithUserEntries.InitialState != null,
                             "Initial state must be stashed to re-create view on round-trip");
                return(View(directDebitDetailsVmWithUserEntries));
            }

            //TODO: Change to async
            var result =
                await _directDebitPlanSetupService.CheckDirectDebitDetails(directDebitDetailsVmWithUserEntries);

            // Restore Payment Options from state embedded in Direct Debit VM
            PaymentOptionsVm paymentOptionsVm = DeserialiseModel <PaymentOptionsVm>(directDebitDetailsVmWithUserEntries.PaymentOptionsFilledInState);

            Debug.Assert(paymentOptionsVm.InitialState == null, "Serialisation Loop Detected - a previous step must have serialised a model that already contains InitialState");

            if (!result.IsSuccessful)
            {
                directDebitDetailsVmWithUserEntries.MessageForUser = result.MessageForUser;

                if (ApplicationSessionState.LogSetUpPlanResult)
                {
                    if (directDebitDetailsVmWithUserEntries.DiscountSelected)
                    {
                        await LogDiscountDirectDebitCompleteFailure(paymentOptionsVm);
                    }
                    else
                    {
                        await LogDirectDebitCompleteFailure(paymentOptionsVm);
                    }

                    ApplicationSessionState.LogSetUpPlanResult = false;
                }

                return(View(directDebitDetailsVmWithUserEntries));
            }

            DirectDebitPlanOverviewVm directDebitPlanOverview = _buildDirectDebitPlanOverviewVmService.Build(paymentOptionsVm, directDebitDetailsVmWithUserEntries);

            // Need to stash direct debit model, so that we can round-trip when 'change' options are selected on confirmation screen.
            Debug.Assert(!string.IsNullOrEmpty(directDebitDetailsVmWithUserEntries.PaymentOptionsFilledInState),
                         "Stashed model MUST contain stashed payment options model, so that it can be round-tripped back to Payment Options if choose to change that");

            directDebitPlanOverview.DirectDebitDetailsFilledInState =
                SerialiseModel(directDebitDetailsVmWithUserEntries);

            _gtmService.RaiseDirectDebitEvent_BankDetails(directDebitPlanOverview, LoggedInUserId, "Direct Debit Plan");

            if (directDebitDetailsVmWithUserEntries.DiscountSelected)
            {
                await LogDiscountDirectDebitDetailsEntered(paymentOptionsVm);
            }
            else
            {
                await LogDirectDebitDetailsEntered(paymentOptionsVm);
            }



            return(View("DirectDebitConfirm", directDebitPlanOverview));
        }