コード例 #1
0
ファイル: ShoppingCart.cs プロジェクト: Neko3000/RabbitHouse
        public int CreateOrder(Order order)
        {
            decimal orderTotal = 0;
            var cartItems = GetCartElements();

            db.Orders.Add(order);
            db.SaveChanges();

            foreach (var item in cartItems)
            {
                var orderDetail = new OrderDetail
                {
                    OrderId = order.Id,
                    Product = item.Product,
                    ProductProperty=item.ProductProperty,
                    UnitPrice = item.Product.Price * (item.Product.CurrentDiscount ?? 1) +(item.ProductProperty.PlusPrice ?? 0),
                    Count = item.Count
                };
                //set the order total of the shopping cart
                orderTotal += (item.Count * item.Product.Price * item.Product.CurrentDiscount ?? 1);

                db.OrderDetails.Add(orderDetail);
            }

            order.Total = orderTotal;
            order.RecordTime = DateTime.Now;
            //save the order
            db.SaveChanges();
            //empty the shopping cart
            EmptyCart();
            //return the Order's Id as the confirmation number
            return order.Id;
        }
コード例 #2
0
        public ActionResult CreateOrder(OrderInfoSubmitViewModel model)
        {
            var cart = ShoppingCart.GetCart(this.HttpContext);
            var order = new Order
            {
                UserId = new Guid(this.HttpContext.User.Identity.GetUserId()),
                PostalCode = model.PostalCode,
                Country = model.Country,
                Province = model.Province,
                City = model.City,
                Locality = model.Locality,
                RecipientName = model.RecipientName,
                PhoneNumber = model.PhoneNumber,
                Email = model.Email,
                Note = model.Note,
                RecordTime = DateTime.Now
            };
            cart.CreateOrder(order);

            return RedirectToAction("Index","UserCenter");
        }