//[ValidateAntiForgeryToken]
        public async Task <IActionResult> Checkout(BasketCheckoutViewModel basketCheckoutViewModel)
        {
            try
            {
                var basketId = Request.Cookies.GetCurrentBasketId(_settings);
                if (ModelState.IsValid)
                {
                    var basketForCheckout = new BasketForCheckout
                    {
                        FirstName      = basketCheckoutViewModel.FirstName,
                        LastName       = basketCheckoutViewModel.LastName,
                        Email          = basketCheckoutViewModel.Email,
                        Address        = basketCheckoutViewModel.Address,
                        Address2       = basketCheckoutViewModel.Address2,
                        City           = basketCheckoutViewModel.City,
                        State          = basketCheckoutViewModel.State,
                        ZipCode        = basketCheckoutViewModel.ZipCode,
                        Country        = basketCheckoutViewModel.Country,
                        CardNumber     = basketCheckoutViewModel.CardNumber,
                        CardName       = basketCheckoutViewModel.CardName,
                        CardExpiration = basketCheckoutViewModel.CardExpiration,
                        CvvCode        = basketCheckoutViewModel.CvvCode,
                        BasketId       = basketId,
                        UserId         = _settings.UserId
                                         //UserId =
                    };

                    await _basketService.Checkout(basketId, basketForCheckout);

                    // clear the basket Id, as it's been removed from the cache on checkout
                    Response.Cookies.Delete(_settings.BasketIdCookieName);

                    return(RedirectToAction("CheckoutComplete"));
                }

                return(View(basketCheckoutViewModel));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMessage = e.Message;
                return(View(basketCheckoutViewModel));
            }
        }
예제 #2
0
        public async Task <IActionResult> Checkout(BasketCheckoutViewModel basketCheckoutViewModel)
        {
            try
            {
                var basketId = Request.Cookies.GetCurrentBasketId(settings);
                if (ModelState.IsValid)
                {
                    var basketForCheckout = new BasketForCheckout
                    {
                        FirstName      = basketCheckoutViewModel.FirstName,
                        LastName       = basketCheckoutViewModel.LastName,
                        Email          = basketCheckoutViewModel.Email,
                        Address        = basketCheckoutViewModel.Address,
                        ZipCode        = basketCheckoutViewModel.ZipCode,
                        City           = basketCheckoutViewModel.City,
                        Country        = basketCheckoutViewModel.Country,
                        CardNumber     = basketCheckoutViewModel.CardNumber,
                        CardName       = basketCheckoutViewModel.CardName,
                        CardExpiration = basketCheckoutViewModel.CardExpiration,
                        CvvCode        = basketCheckoutViewModel.CvvCode,
                        BasketId       = basketId,
                        UserId         = Guid.Parse(
                            User.Claims.FirstOrDefault
                                (c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier")?.Value)
                    };

                    await basketService.Checkout(basketCheckoutViewModel.BasketId, basketForCheckout);

                    return(RedirectToAction("CheckoutComplete"));
                }

                return(View(basketCheckoutViewModel));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMessage = e.Message;
                return(View(basketCheckoutViewModel));
            }
        }
예제 #3
0
        public async Task <IActionResult> Checkout(BasketCheckoutViewModel basketCheckoutViewModel)
        {
            using var scope = logger.BeginScope("Checking out basket {BasketId}", basketCheckoutViewModel.BasketId);

            try
            {
                var basketId = Request.Cookies.GetCurrentBasketId(settings);
                if (ModelState.IsValid)
                {
                    var basketForCheckout = new BasketForCheckout
                    {
                        FirstName      = basketCheckoutViewModel.FirstName,
                        LastName       = basketCheckoutViewModel.LastName,
                        Email          = basketCheckoutViewModel.Email,
                        Address        = basketCheckoutViewModel.Address,
                        ZipCode        = basketCheckoutViewModel.ZipCode,
                        City           = basketCheckoutViewModel.City,
                        Country        = basketCheckoutViewModel.Country,
                        CardNumber     = basketCheckoutViewModel.CardNumber,
                        CardName       = basketCheckoutViewModel.CardName,
                        CardExpiration = basketCheckoutViewModel.CardExpiration,
                        CvvCode        = basketCheckoutViewModel.CvvCode,
                        BasketId       = basketId,
                        UserId         = settings.UserId
                    };

                    await basketService.Checkout(basketId, basketForCheckout);

                    return(RedirectToAction("CheckoutComplete"));
                }

                return(View(basketCheckoutViewModel));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMessage = e.Message;
                return(View(basketCheckoutViewModel));
            }
        }
예제 #4
0
        public async Task <IActionResult> Checkout(BasketCheckoutViewModel basketCheckoutViewModel)
        {
            try
            {
                //User.TryGetClaim(JwtClaimTypes.Subject, out Guid userId);
                var basketId = Request.Cookies.GetCurrentBasketId(settings);
                if (ModelState.IsValid)
                {
                    var basketForCheckout = new BasketForCheckout
                    {
                        FirstName      = basketCheckoutViewModel.FirstName,
                        LastName       = basketCheckoutViewModel.LastName,
                        Email          = basketCheckoutViewModel.Email,
                        Address        = basketCheckoutViewModel.Address,
                        ZipCode        = basketCheckoutViewModel.ZipCode,
                        City           = basketCheckoutViewModel.City,
                        Country        = basketCheckoutViewModel.Country,
                        CardNumber     = basketCheckoutViewModel.CardNumber,
                        CardName       = basketCheckoutViewModel.CardName,
                        CardExpiration = basketCheckoutViewModel.CardExpiration,
                        CvvCode        = basketCheckoutViewModel.CvvCode,
                        BasketId       = basketId,
                        // UserId = userId,
                    };

                    await basketService.Checkout(basketCheckoutViewModel.BasketId, basketForCheckout);

                    return(RedirectToAction("CheckoutComplete"));
                }

                return(View(basketCheckoutViewModel));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMessage = e.Message;
                return(View(basketCheckoutViewModel));
            }
        }