示例#1
0
        public DetailSale ToDetailSale()
        {
            DetailSale detailSale = new DetailSale()
            {
                saleCount     = this.count,
                subTotal      = this.subTotal,
                detailProduct = new DetailProduct {
                    idDetailProduct = this.idDetailProduct
                }
            };

            return(detailSale);
        }
示例#2
0
        public int CreateSale(Sale order)
        {
            decimal orderTotal = 0;

            var cartItems = GetCartItems();

            // Iterate over the items in the cart, adding the order details for each
            foreach (var item in cartItems)
            {
                var orderDetail = new DetailSale
                {
                    ProductID = item.ProductID,
                    SaleID = order.SaleID,
                    Price = item.Price,
                    Amount = item.Amount
                };

                // Set the order total of the shopping cart
                orderTotal += (item.Amount * item.Price);

                db.DetailSales.AddObject(orderDetail);

            }

            order.Creation = DateTime.Now;

            // Set the order's total to the orderTotal count
            order.Total = orderTotal;

            // Save the order
            db.SaveChanges();

            // Empty the shopping cart
            EmptyCart();

            // Return the OrderId as the confirmation number
            return order.SaleID;
        }