Sunday 3 May 2009

An update on the shopping cart demo

Well the first version of this demo (here) was targeted at the 2.0 version of the .NET framework, this version is for the 3.5 version.

A few changes and additions were made.

Firstly I changed the layout of the projects now to use a common namespace and put the different classes in folders to represent their functional types. Also they have being strongly named and signed with a keyfile. (Password is password). Using this means you can install the assemblies to the GAC if required.

I added a new property to the CartItem class that returns the total cost of the item in the shopping cart

        public int TotalPrice
            get { return Amount*Cost; }

I changed how the generic object filler works. Instead of using the names of the properties of the object, it now uses what you returned in the datarow making it a bit more flexible.

I updated the Catalog.aspx file to now show the shopping cart which will also show the cost of the items in the cart as well as the actual amount of items in the cart rather than the list count.

I have also used a Lambda expression where before I used an anonymous method

var hasitem = cartItems.Find((ci => ci.Id == cartItem.Id));

Included now is a very simple cascading dropdown demo which shows how to do it and also how you can link products to the values in the database.

Later I will show how to do this using Ajax.

Also there is a copy of the config.aspx tool that I use to protect the connection string in the web.config. This tool and how it works is explained here

You can download the updated solution from here

Installation notes.

You will need to create a database first and then use the SQL script in the root of the solution folder to create the tables and stored procedures.

You may also have to adjust the connection string in the web.config file to suit your own installation.

If you are prompted for a password for the keyfiles, type in password

No comments: