public async Task<ActionResult> Checkout(CheckoutViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var cart = new ShoppingCart(HttpContext);

            var result = await cart.CheckoutAsync(model);

            return RedirectToAction("index");
        }
コード例 #2
0
        public async Task<ActionResult> Checkout(CheckoutViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);                   
            }

            var cart = new ShoppingCart(HttpContext);

           var result = await cart.CheckoutAsync(model); 

            if (result.Succeeded)
            {
                TempData["transactionId"] = result.TransactionId;
                return RedirectToAction("Complete");
            }

            ModelState.AddModelError(string.Empty, result.Message);

            return View(model);
        }
        public async Task<object> CheckoutAsync(CheckoutViewModel model)
        {
            var items = await GetCartItemsAsync();
            var order = new Order()
            {
                FirstName = model.FirstName,
                LastName = model.LastName,
                Address = model.Address,
                City = model.City,
                State = model.State,
                PostalCode = model.PostalCode,
                Country = model.Country,
                Phone = model.Phone,
                Email = model.Email,
                OrderDate = DateTime.Now
            };

            foreach (var item in items)
            {
                var detail = new OrderDetail()
                {
                    ProductId = item.ProductId,
                    UnitPrice = item.Product.Price,
                    Quantity = item.Count
                };

                order.Total += (item.Product.Price*item.Count);

                order.OrderDetails.Add(detail);
            }

            // TODO: authorize payment
            // TODO: assign the transactionid

            _db.Orders.Add(order);
            //await _db.SaveChangesAsync();
            return null;
        }
コード例 #4
0
        public async Task<PaymentResult> CheckoutAsync(CheckoutViewModel model)
        {
            var items = await GetCartItemsAsync(); 
            var order = new Order()
            {
                FirstName = model.FirstName,
                LastName = model.LastName,
                Address = model.Address,
                City = model.City,
                State = model.State,
                PostalCode = model.PostalCode,
                Country = model.Country,
                Phone = model.Phone,
                Email = model.Email,
                OrderDate = DateTime.Now
            };

            foreach (var item in items)
            {
                var detail = new OrderDetail()
                {
                    ProductId = item.ProductId,
                    UnitPrice = item.Product.Price,
                    Quantity = item.Count
                };

                order.Total += (item.Product.Price * item.Count);

                order.OrderDetails.Add(detail);
            }

            var gateway = new PaymentGateway();
            var result = gateway.ProcessPayment(model); 

            if (result.Succeeded)
            {
                order.TransactionId = result.TransactionId;
                _db.Orders.Add(order);
                _db.CartItems.RemoveRange(items);
                await _db.SaveChangesAsync();

            }
            return result;
        }