This project is read-only.

Purpose of GetCart Helper Method [ and GetCart(HttpContextBase context)]

May 24, 2011 at 7:17 AM
Edited May 24, 2011 at 7:19 AM

Working through all 135 pages of the tutorial in detail.

Was going great until I got to section 8.

Please go to the shopping cart class.

Due to the my lack of expereince with the subject, I can't understand the purpose of the helper method below.


Also, not clear on the two GetCart methods. I know they are overridden with different signatures, it is just not registering with me why.


Can someone help my old brain.

 This text does not seem to be enough for it to gel with me:

GetCart is a static method which allows our controllers to obtain a cart object. It uses the GetCartId method to handle reading the CartId from the user’s session. The GetCartId method requires the HttpContextBase so that it can read the user’s CartId from user’s session.


        public static ShoppingCart GetCart(HttpContextBase context) 
            var cart = new ShoppingCart(); 
            cart.ShoppingCartId = cart.GetCartId(context); 
            return cart; 
        // Helper method to simplify shopping cart calls 
        public static ShoppingCart GetCart(Controller controller) 
            return GetCart(controller.HttpContext); 

May 29, 2011 at 12:49 AM

I really need some further help understanding this.

Why can't I just call the session variable directly like I used to do in old ASP.

My basis for knowledge is classic asp.  Just a little before MVC.