Skip to content

Instantly share code, notes, and snippets.

@kmckelvin
Created August 28, 2010 08:15
Show Gist options
  • Save kmckelvin/554889 to your computer and use it in GitHub Desktop.
Save kmckelvin/554889 to your computer and use it in GitHub Desktop.
public int CreateOrder(Order order)
{
using (var tx = storeDB.Session.BeginTransaction())
{
var cartItems = GetCartItems();
//Iterate the items in the cart, adding Order Details for each
foreach (var cartItem in cartItems)
{
var orderDetail = new OrderDetail
{
Album = cartItem.Album,
Order = order,
UnitPrice = cartItem.Album.Price
};
order.OrderDetails.Add(orderDetail);
}
//Save the order
storeDB.Session.Save(order);
tx.Commit();
}
//Empty the shopping cart
EmptyCart();
//Return the OrderId as a confirmation number
return order.OrderId;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment