Monday, February 7, 2011

Shopping Cart in MVC2

Download Source


Problem
Classic ASP.Net has a convoluted programming model.

Solution
MVC2 is a better programming model for a shopping cart app. This project is a complete Shopping Cart. I evaluated how much work it was going to be to write the app in ASP (even though I worked with ASP for a long time) and I realised that writing it in MVC2 would be easier.

I'm not going to go in to technique too much here. The code here speaks for itself so please download the source code. However, I will give some info on the different technology this website uses.

By the way, if you need to create an MVC2 Shopping Cart, I strongly recommend having a look at this code because you will have most of the fundamental functioanlity here. The functionality allows for user administration and editing products.

MVC2
MVC2 Divides models (classes that house data), views (ASCX pages) and controllers. Controllers are code files that control the way the view works. This division makes coding in ASP a lot cleaner. There are also some other advantages. It also makes dynamic page updates a lot cleaner. I was never a fan of the UpdatePanel in ASP. While in MVC2, you can do a partial page update on an ASCX withou needing anything like an UpdatePanel.

Silverlight & RIA
The sample app has some Silverlight Charts using RIA Services. This is a good example of how Silverlight can be added in to an MVC2 app in order to provide a nicer UI.

Entity Framework
The backend uses EF to persist data. I found this data layer a bit clunky but I like the way you can do very sophisticated LINQ queries on the data and the data layer remains database independent.

LINQ & Lambda
I used loads of LINQ and lambda to show of how well EF works with these technologies.

Sitemap
This sitemap library is a 3rd party tool.

Partial Page Rendering without JavaScript
ASP MVC2 makes partial page rendering very simple. It has a clean model for partial updates without having to write the actual JavaScript in many cases.
Data Paging (Partial Rendering)
The data paging library is a 3rd party tool.

ASP Membership Provider
This app uses the ASP membership database and is separated from the app database. There is a script provided to create both databases from scratch. The application pays attention to roles and gives the "Admin" user differernt privildeges.

SQL Server
That's obvious.

WCF
There is a dummy payment service to mock up a credit card payment system.

Get It Running

  • Run the script shopping_cart.sql in SQL Server. I used SQL Server 2008 but I think it will work in 2005 as well. (Check that the path for the files exist - 'c:\Databases' )
  • Open the solution.
  • Point the web.config at the databases on your local machine
  • Run
  • Log in as "Admin/admin", or "Andreat/aaaaaa", or create a new profile. Note: the different options as an admin user


Download Source

No comments:

Post a Comment