MvcMusicStore.Models.ShoppingCart.CreateOrder C# (CSharp) Method

CreateOrder() public method

Retorna o Id de uma compra, passada no parâmetro, como confirmação.
public CreateOrder ( Order order ) : ulong
order Order
return ulong
        public ulong CreateOrder(Order 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 OrderDetail
                {
                    Album = item.Album,
                    Order = order,
                    UnitPrice = item.Album.Price,
                    Quantity = item.Count
                };

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

                orderDetail.Save();

            }

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

            // Save the order
            order.Save();

            // Empty the shopping cart
            EmptyCart();

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