This project is read-only.

Should CreateOrder in ShoppingCart model set OrderDetail.Quantity?

Jan 18, 2011 at 10:55 PM

I ran through the tutorial which has been very helpful in understanding MVC.  The PDF is wonderfully complete, thanks for putting it together.

After creating and checking out a cart, I noticed that all the fields in OrderDetail were filled in except Quantity, which was 0.  I think the problem is that CreateOrder in the ShoppingCart model should set OrderDetail.Quantity = cartItem.Count.  

Is this the correct fix?

      public int CreateOrder(Order order)
            decimal orderTotal = 0;

            var cartItems = GetCartItems();

            //Iterate the items in the cart, adding Order Details for each
            foreach (var cartItem in cartItems)
                var orderDetails = new OrderDetail
                    AlbumId = cartItem.AlbumId,
                    OrderId = order.OrderId,
                    UnitPrice = cartItem.Album.Price,
                    Quantity= cartItem.Count


                orderTotal += (cartItem.Count * cartItem.Album.Price);

            //Save the order

            //Empty the shopping cart

            //Return the OrderId as a confirmation number
            return order.OrderId;


Jan 27, 2011 at 1:19 AM

Yes, that's correct. It looks like you were using the 1.0 release of the tutorial, as this fix is included in the 2.0 release.

Feb 1, 2011 at 11:47 PM

Hi Jon,
I've run into several issues related to the CreatorOrder function I need your help with.
First... just an FYI for going forward the,   storeDB.OrderDetails.Add(orderDetails);  line is not present in either the completed code or in the version 2 of the tutorial.
Also on page 128 there is a reference to    storeDB.AddToOrders(order);   that should be    storeDB.Orders.Add(order);   Most everyone has resolved these two issues on their own but there is one that I've seen several people comment on but I haven't seen anyone come up with what looks like the correct way to solve the issue.
And that would be getting the total in the order table to update. I'm still looking for a solution but any help you can provide would be appreciated.

Thanks again Jon for the great tutorial 

Feb 14, 2011 at 3:52 PM

Any luck resolving this issue?

Apr 7, 2011 at 1:38 AM
Edited Apr 7, 2011 at 1:39 AM

@madisonJames - Thanks - I've made these corrections for the next release

@justSteve - Which issue are you asking about? There are several listed here.

Jan 4, 2012 at 3:31 PM

Hi, i have been following the MVC tutorial and I'm wondering if the shopping cart can be altered in such a way to allow more quantities to be added in the cart. Instead of having to go back to the Products page and clicking the album again to increase quantity.

How do i allow shopping cart to insert more quantity?