Esempio n. 1
0
        public async Task <IActionResult> Checkout()
        {
            CartCheckoutViewModel checkoutViewModel = new CartCheckoutViewModel
            {
                Customers = await _NorthwindDAL.GetCustomersAsync(),
                Employees = await _NorthwindDAL.GetEmployeessAsync(),
                Shippers  = await _NorthwindDAL.GetShippersAsync()
            };

            return(View(checkoutViewModel));
        }
Esempio n. 2
0
        public IActionResult Receipt(CartCheckoutViewModel cartCheckout)
        {
            //int employeeID = cartCheckout.EmployeeID;
            //int shipperID = cartCheckout.ShipperID;
            //string customerID = cartCheckout.CustomerID;

            //create order
            DateTime orderDate = DateTime.Now;
            Order    order     = new Order();
            var      cart      = CartDAL.GetCart(HttpContext.Session);

            order.CustomerID   = cartCheckout.CustomerID;
            order.EmployeeID   = cartCheckout.EmployeeID;
            order.Freight      = 10 + (cart.Count * 1);
            order.OrderDate    = orderDate;
            order.RequiredDate = DateTime.Now.AddDays(7);
            //order.ShippedDate = DateTime.Now.AddDays(5);// filled out in Admin section
            order.ShipVia = cartCheckout.ShipperID;

            if (cartCheckout.CustomerID != null)
            {
                Customer customer = _NorthwindDAL.GetCustomer(cartCheckout.CustomerID);
                order.ShipName       = customer.ContactName; // cartCheckout.Name;
                order.ShipAddress    = customer.Address;     // cartCheckout.Address;
                order.ShipCity       = customer.City;        // cartCheckout.City;
                order.ShipRegion     = customer.Region;      // cartCheckout.State;
                order.ShipPostalCode = customer.PostalCode;  // cartCheckout.PostalCode;
                order.ShipCountry    = customer.Country;
            }

            int orderID = _NorthwindDAL.AddOrder(order).Value;

            for (int i = 0; i < cart.Count; i++)
            {
                OrderDetail orderDetail = new OrderDetail();
//                orderDetail.Discount = 0;
                orderDetail.OrderID   = orderID;
                orderDetail.ProductID = cart[i].Product.Id;
                orderDetail.Quantity  = cart[i].Quantity;
                orderDetail.UnitPrice = cart[i].Product.Price;
                _NorthwindDAL.AddOrderDetail(orderDetail);
            }

            CartReceiptViewModel receipt = new CartReceiptViewModel
            {
                OrderID   = orderID,
                OrderDate = orderDate
            };

            //clear cart
            CartDAL.SetCart(HttpContext.Session, null);

            return(View(receipt));
        }
Esempio n. 3
0
        public async Task <IActionResult> Checkout([FromRoute] Guid id, [FromBody] CartCheckoutViewModel checkout)
        {
            var xTeamControl = Request.Headers["x-team-control"].FirstOrDefault();

            if (string.IsNullOrWhiteSpace(xTeamControl))
            {
                return(new FailureActionResult(HttpStatusCode.BadRequest, "'x-team-control' header is missing"));
            }

            return(await _cartService.Checkout(id, checkout.CurrencyCode, xTeamControl));
        }
Esempio n. 4
0
        public IActionResult Checkout()
        {
            IEnumerable <Address> addList = _addressService.GetAll();
            IEnumerable <Product> proList = _productService.GetAll();

            CartCheckoutViewModel vm = new CartCheckoutViewModel();

            vm.Addresses = new SelectList(addList, "AddressId", "HouseAddress");

            return(View(vm));
        }
Esempio n. 5
0
        public async Task <IActionResult> Checkout()
        {
            ApplicationUser user = await _UserManager.GetUserAsync(HttpContext.User);

            CartCheckoutViewModel vm = new CartCheckoutViewModel
            {
                Addresses    = _AddressDataService.GetAll().Where(a => a.CustomerId == user.Id),
                HamperOrders = SessionHelper.GetObectFromJson <IEnumerable <HamperOrder> >(HttpContext.Session, "cart")
            };

            return(View(vm));
        }
Esempio n. 6
0
        public async Task <IActionResult> Checkout(CartCheckoutViewModel vm)
        {
            if (ModelState.IsValid)
            {
                vm.HamperOrders = SessionHelper.GetObectFromJson <IEnumerable <HamperOrder> >(HttpContext.Session, "cart");
                ApplicationUser user = await _UserManager.GetUserAsync(HttpContext.User);

                Order o = new Order
                {
                    OrderDate         = DateTime.Now,
                    ApplicationUserId = user.Id,
                };
                _OrderDataService.Add(o);

                foreach (HamperOrder hamperOrder in vm.HamperOrders)
                {
                    hamperOrder.OrderId = o.OrderId;
                    hamperOrder.Hamper  = null;
                    _HamperOrderDataService.Add(hamperOrder);
                }
                return(RedirectToAction("Success"));
            }
            return(View(vm));
        }
Esempio n. 7
0
        public IActionResult Checkout(CartCheckoutViewModel vm)
        {
            if (ModelState.IsValid)
            {
                List <OrderItem> cart = HttpContext.Session.GetObjectFromJson <List <OrderItem> >("cart");


                Order ord = new Order
                {
                    Items     = vm.Items,
                    OrderId   = vm.OrderId,
                    AddressId = vm.AddressId,
                };

                List <OrderItem> items = new List <OrderItem>();

                foreach (var item in cart)
                {
                    var cartItem = new OrderItem()
                    {
                        OrderId   = item.OrderId,
                        ProductId = item.Product.ProductId,
                        Quantity  = item.Quantity,
                        SubTotal  = item.SubTotal,
                    };
                    items.Add(cartItem);
                }

                ord.Items = items;

                _orderService.Create(ord);

                return(RedirectToAction("Index", "Home"));
            }
            return(View(vm));
        }