示例#1
0
        public int CreateOrder(OrderDetail orderDetail, string cusId)
        {
            orderDetail.CustomerId = cusId;
            orderDetail.OrderDate  = DateTime.Now;
            orderDetail.Total      = this.TotalPrice();
            orderDetail.Status     = GreenSol.Domain.Entities.Status.Processing;

            repository.CreateOrderDetail(orderDetail);

            var cartLines = this.CartLines();

            // Iterate over the items in the cart, adding the order details for each
            foreach (var item in cartLines)
            {
                Album album = repository.Albums.Single(a => a.AlbumId == item.AlbumId);

                var order = new Order
                {
                    AlbumId   = item.AlbumId,
                    OrderId   = orderDetail.OrderDetailId,
                    UnitPrice = album.Price,
                    Quantity  = item.Count,
                };
                repository.CreateOrder(order);
            }

            // Empty the shopping cart
            //EmptyCart();

            // Return the OrderId as the confirmation number
            return(orderDetail.OrderDetailId);
        }