Пример #1
0
        public ViewResult Checkout(CartViewModel cart, User user, Order order)
        {
            if (cart.OrdersDetails.Count() == 0)
            {
                ViewBag.IsSuccess = false;
                ViewBag.Message = "Sorry, your cart is empty!";
            }
            else
            {
                ViewBag.IsSuccess = true;
                ViewBag.Message = "Thanks for placing your order. We'll ship your goods as soon as possible.";

                using (InternetStoreDBContext dbc = new InternetStoreDBContext())
                {
                    if (!User.Identity.IsAuthenticated)
                    {
                        dbc.Users.InsertOnSubmit(user);
                        dbc.SubmitChanges();
                        order.UserID = user.ID;
                    }
                    else
                    {
                        User currentUser = (from u in dbc.Users where u.Email == User.Identity.Name select u).ToList().FirstOrDefault();
                        order.UserID = currentUser.ID;
                    }

                    order.ShippingDate = DateTime.Now.ToOADate();
                    if (order.ShippingStatus == null)
                        order.ShippingStatus = "Check";
                    dbc.Orders.InsertOnSubmit(order);
                    dbc.SubmitChanges();

                    Sale sale = new Sale() { OrderID = order.ID, SalesAmount = cart.ComputeTotalValue() };
                    dbc.Sales.InsertOnSubmit(sale);
                    dbc.SubmitChanges();

                    foreach (var orderDetails in cart.OrdersDetails)
                    {
                        var orderDetails2 = new OrderDetails() { OrderID = order.ID, ProductID = orderDetails.ProductID, Quantity = orderDetails.Quantity };
                        dbc.OrderDetails.InsertOnSubmit(orderDetails2);
                        dbc.SubmitChanges();
                    }

                    cart.Clear();
                }
            }

            ViewBag.IsAuthenticated = User.Identity.IsAuthenticated;
            return View();
        }
Пример #2
0
 public ViewResult Checkout(User user, Order order)
 {
     ViewBag.IsAuthenticated = User.Identity.IsAuthenticated;
     return View();
 }