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

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

Working through all 135 pages of the tutorial in detail.

Was going great until I got to section 8.

 

http://www.asp.net/mvc/tutorials/mvc-music-store-part-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 28, 2011 at 11:49 PM

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 asp.net before MVC.