public async Task <IActionResult> Contact(ContactViewModel model)
        {
            if (string.IsNullOrWhiteSpace(model.Name) ||
                string.IsNullOrWhiteSpace(model.Email) ||
                string.IsNullOrWhiteSpace(model.Subject) ||
                string.IsNullOrWhiteSpace(model.Message)
                )
            {
                model.FailureMessage = "Please complete all fields.";

                return(View(model));
            }

            if (string.IsNullOrWhiteSpace(model.RecaptchaResponse))
            {
                model.FailureMessage = "Something went wrong, please try again.";

                return(View(model));
            }

            if (!RecaptchaHelper.IsReCaptchValid(model.RecaptchaResponse))
            {
                model.FailureMessage = "Something went wrong, please try again.";

                return(View(model));
            }

            var messageText = string.Format("Message from {0}{1}{2}", model.Email, System.Environment.NewLine, model.Message);
            await _emailSender.SendEmailAsync(MasterStrings.AdminEmail, model.Subject, messageText);

            var redirectUrl = string.Format("/Home/Contact?successMessage=Your message '{0}' has been sent.", model.Subject);

            return(ControllerHelper.RedirectToLocal(this, redirectUrl));
        }
        public ActionResult Index(CheckoutViewModel model)
        {
            var cart = cartProvider.GetCart();
            var contactDataCollection = contactDataProvider.GetContactData();

            ViewBag.CheckVAT = !String.IsNullOrEmpty(vatDataProvider.VatNumber);

            if (RecaptchaHelper.IsRecaptchaEnabled())
            {
                if (!RecaptchaHelper.IsResponseValid(Request.Form["g-recaptcha-response"]))
                {
                    ModelState.AddModelError("recaptcha", this.GlobalCommonResource("RecaptchaVerificationFaild"));
                }
            }

            if (cart.IsEmpty())
            {
                ModelState.AddModelError("cart", "Cart is empty");
            }
            else if (contactDataCollection == null)
            {
                ModelState.AddModelError("contactData", "Contact data is empty");
            }

            if (ModelState.IsValid)
            {
                // Recalculate cart one last time, to make sure e.g. setup fees are still there.
                cartPricingService.CalculatePricing(cart);

                var paymentData = new PaymentData
                {
                    Id          = model.SelectedPaymentMethod.Id,
                    PaymentForm = model.SelectedPaymentMethod.Form,
                    SaveCcInfo  = model.SelectedPaymentMethod.SupportsPaymentProfile && model.SaveCcInfo,
                    AutoPay     = model.SelectedPaymentMethod.SupportsPaymentProfile && model.AutoPay
                };

                var orderContext = new OrderContext(cart, contactDataCollection, paymentData, new object[] { Request });
                var result       = orderPlacementService.PlaceOrder(orderContext);

                if (result.RedirectUrl == urlProvider.SuccessUrl)
                {
                    contactDataProvider.ClearContactData();
                    cartProvider.ClearCart();
                }

                return(Redirect(result.RedirectUrl));
            }

            if (RecaptchaHelper.IsRecaptchaEnabled())
            {
                ViewBag.RecaptchaEnabled = true;
                ViewBag.RecaptchaSiteKey = RecaptchaHelper.GetSiteKey();
            }

            ViewData["formHasErrors"] = true;
            return(View(model));
        }
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                if (string.IsNullOrWhiteSpace(Input.RecaptchaResponse))
                {
                    Input.FailureMessage = "Something went wrong, please try again.";
                    Input.Titles         = CustomerTitle.GetTitles(_context.Titles.Where(c => c.Id > 0).OrderBy(x => x.Value).ToList());
                    return(Page());
                }

                if (!RecaptchaHelper.IsReCaptchValid(Input.RecaptchaResponse))
                {
                    Input.FailureMessage = "Something went wrong, please try again.";
                    Input.Titles         = CustomerTitle.GetTitles(_context.Titles.Where(c => c.Id > 0).OrderBy(x => x.Value).ToList());
                    return(Page());
                }

                var user = new ApplicationUser {
                    UserName = Input.Email,
                    Email    = Input.Email,
                    Forename = Input.Forename,
                    Surname  = Input.Surname,
                    Title    = Input.Title
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(LocalRedirect(returnUrl));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            Input.FailureMessage = "Something went wrong, please try again.";
            Input.Titles         = CustomerTitle.GetTitles(_context.Titles.Where(c => c.Id > 0).OrderBy(x => x.Value).ToList());
            return(Page());
        }
        public ActionResult Index()
        {
            // Make sure cart is properly calculated.
            var cart = cartProvider.GetCart();

            cartPricingService.CalculatePricing(cart);

            // If VAT number was submitted, indicate a VAT check should be made
            ViewBag.CheckVAT = !string.IsNullOrEmpty(vatDataProvider.VatNumber);
            if (RecaptchaHelper.IsRecaptchaEnabled())
            {
                ViewBag.RecaptchaEnabled = true;
                ViewBag.RecaptchaSiteKey = RecaptchaHelper.GetSiteKey();
            }

            var model = DependencyResolver.Current.GetService <CheckoutViewModel>();

            ViewData["formHasErrors"] = false;

            return(View(model));
        }