コード例 #1
0
        public virtual async Task <ActionResult> Index(FormCollection formValues)
        {
            BicycleQuote quote = new BicycleQuote();

            TryUpdateModel(quote, formValues);

            IEnumerable <ErrorInfo> errors = ViewModelValidator.Validate(quote.Question, "Question");

            ModelStateUtil.AddModelStateErrors(ViewData.ModelState, errors, null, x => true, GetQuestionError);

            if (!ModelState.IsValid)
            {
                ViewData.SetReferenceData(_questionFormHandler.CreateReferenceData());

                return(ValidationError(quote));
            }

            // do this after validation, no point creating a policy if the form is invalid.
            long?     policyId = this.GetPolicyId(false);
            PolicyDTO policy;

            if (policyId == null)
            {
                policy = await _questionFormHandler.CreatePolicy(quote.Question);

                this.SetPolicyId(policy.Id);
            }
            else
            {
                policy = await _questionFormHandler.UpdatePolicy(policyId, quote.Question);
            }

            return(NavigateToAction(LocalMVC.Quote.Index()));
        }
コード例 #2
0
        public virtual async Task <ActionResult> Index(FormCollection formValues)
        {
            BicycleQuote model = new BicycleQuote();

            TryUpdateModel(model, formValues);

            long?policyId = this.GetPolicyId();

            Result <Transaction> transaction = await _paymentFormHandler.ProcessPayment(policyId, model.PolicyPayment.PaymentDetails.BrainTree.payment_method_nonce);

            if (transaction != null && transaction.IsSuccess())
            {
                model.PolicyPayment.PaymentDetails.BrainTree.PaymentFailed = false;
                await _paymentFormHandler.IssuePolicy(policyId, transaction);
            }
            else
            {
                model.PolicyPayment.PaymentDetails.BrainTree.PaymentFailed = true;
            }

            // validate model
            IEnumerable <ErrorInfo> errors = ViewModelValidator.Validate(model.PolicyPayment, "PolicyPayment");

            ModelStateUtil.AddModelStateErrors(ViewData.ModelState, errors, null, x => true, GetQuestionError);

            if (ModelState.IsValid) // continue if payment succeeded
            {
                return(NavigateToAction(LocalMVC.Confirmation.Index()));
            }
            else
            {
                await _paymentFormHandler.UpdateModelFromDto(this.GetPolicyId(), model);

                ViewData.SetReferenceData(_paymentFormHandler.CreateReferenceData());

                model.PolicyPayment.PaymentDetails.BrainTree.ClientToken = _paymentFormHandler.GetBraintreeClientToken();

                return(ValidationError(model));
            }
        }
コード例 #3
0
        public virtual async Task <ActionResult> Index(FormCollection formValues)
        {
            BicycleQuote quote = new BicycleQuote();

            TryUpdateModel(quote, formValues);

            IEnumerable <ErrorInfo> errors = ViewModelValidator.Validate(quote.PolicyDetail, "PolicyDetail");

            ModelStateUtil.AddModelStateErrors(ViewData.ModelState, errors, null, x => true, GetQuestionError);

            if (!ModelState.IsValid)
            {
                PolicyDTO policy = await _policyDetailFormHandler.GetPolicy(this.GetPolicyId());

                SetReferenceData(policy, quote);

                return(ValidationError(quote));
            }

            await _policyDetailFormHandler.UpdateContactDetails(this.GetPolicyId(), quote);

            return(NavigateToAction(LocalMVC.Payment.Index()));
        }