Online Storefront with MVC 3 / Razor (Create the Project) – 2

by Aref Thu, November 25 2010 18:42

Welcome back, this is part 2 of the MVC 3 / Razor storefront series. In this post, we will set up the project, create the database structure and set up some folders.

To begin, I will assume that you have installed the MVC 3 Release Candidate bits. If not, you can get it at http://bit.ly/h1hGym My development environment is Visual Studio.NET Ultimate 2010. You will need .NET 4 (Framework), ASP.NET 4 and Visual Studio.NET 2010 or Visual Web Developer 2010 to develop this particular solution. As part of the MVC 3 installation, you will also get the wonderful open source, package manager, NuGet. This greatly simplifies the installation of extensions (and we may need some). Also, I am using SQL Server 2008 Express Edition for this solution.

Okay, let’s get going…

1. Creating the project

Create a new project and choose the “ASP.NET MVC 3 Web Application” template as shown below.

 

2. Choose the project template

Clicking on OK will launch the choice dialog box for selecting the project template as shown below.

 

Go ahead, and choose the “Internet Application” template. You may additionally check the “Create a unit test project” check box but I will skip TDD for this project.

2. Creating the MembershipProvider support

Now run the application by hitting the F5 key and it should launch under the local ASP.NET Development server over a non-standard port. Viola! Here is your application with the ability to login, and register.

 

Now, register a new user by first clicking on the “Log On” link at the top right corner of your application and then on the “Register” link in the subsequent page. I created a user called Admin for now.

 

Clicking on the Register button will in turn create a database called ASPNETDB under the App_Data folder. Let us add this to our solution explorer by right clicking the App_Data folder and adding an existing item and choosing the ASPNETDB.MDF file to be added. You should now be able to double click on the ASPNETDB database under the solution explorer and have it appear under the “Data Connections” window.

 This will also create a connection string called “ApplicationServices” in the web.config to the default ASPNETDB database to support the MembershipProvider. In fact, the Membership, Profile and roleManager providers all point to this connection. For this project, we will add our own store schema to the same database. (I may cover how to use your own custom Membership provider with your own database or you may look it up on the internet).

3. Creating the database schema

We will now add the required tables to the database. Specifically we will add the following:

TABLES

Customer

Product

Category

Cart

Order

OrderItems

The entire database is attached and you may download it.

4. Creating the Entity Framework Model

Now we will create an entity framework model from our database schema. To do this, we will

1. Right click on the Models folder within the Solution Explorer and click on add… new item.

 

2. Click on Add and then choose “Generate from Database”

 

3. In the Entitiy Data Model Wizard, (which like a wizard recognizes your database from the connection settings defined in the web.config), change the entity connection settings name to MystoreEntities and click on Next.

 

4. In the “Choose Your Database Objects” step, select the following tables and change the Model Namespace to “MystoreModel”.

Cart, Category, Customer, Order, OrderItems, Product as shown below.

 

5. Now click on Finish to close the wizard and have the EF object model created. You will now see the object model generated as the edmx file as shown below.

 

Conclusion and next steps…

So, we have just created a blank MVC 3 / Razor solution, added a database with membership and role support and support for the online store. We then exposed this as an object data model using the Entity Framework.

Next time, we will create some templates, add validation at the model level and showcase some (featured) products on the home page using the model-view-controller.

Until next time, take care…

App_Data.zip (234.58 kb)

 

Tags: , ,

.NET MVC

Comments

11/29/2010 9:09:43 PM #

Satish

Hey! That’s a really great post. I’m very sure I will suggest it to my co-workers.If you post more posts please email them to me.

Satish United States |

12/2/2010 4:36:44 PM #

Aref Moin

Finally got the captcha working thanks to the suggestions on the extension website. However there was a conflict with duplicate methods/namespaces declared under controls and extensions. Just deleted all the ones under extensions, added my pub/private keys and now it works. Hopefully this will avoid the delude of spam I've been getting lately.

Aref Moin Canada |

12/3/2010 12:31:04 AM #

trackback

Using MVC 3 and Razor

You've been kicked (a good thing) - Trackback from DotNetKicks.com

DotNetKicks.com |

5/19/2011 9:53:23 AM #

webdesigner

much appreciated..good job

webdesigner United States |

6/12/2011 8:55:07 PM #

Christian Louboutin

Hey! That’s a really great post. I’m very sure I will suggest it to my co-workers.If you post more posts please email them to me.

Christian Louboutin United States |

6/25/2011 2:17:54 AM #

Beats Headphones


a nice and informative post ,you are doing an excellent job with your site let it keep coming. i like your blog ,thanks !!

Beats Headphones People's Republic of China |

Comments are closed