We pay for user submitted tutorials and articles that we publish. Anyone can send in a contributionLearn More
Today’s article is going to be one of many, or at least a few, that take a look at building an application using the new ASP.Net MVC Beta. I wanted to do this in a small series so we can look at each phase of the application in a decent amount of detail while keeping the length appropriate for a blog post.
This first part isn’t actually going to crack the lid on MVC just yet but we are going to look at a few things today.
Model-View-Controller is a design pattern that separates business logic from user interface logic. This separation allows for easier maintenance of the application. The models deal with the data and business rules that manipulate the data. Views represent the user interface and logic that handles user interaction such as mouse clicks and keyboard input. Finally, controllers manage all communication between models and views. In an ideal implementation models don’t know anything about views and vice versa, the controllers handle all of this.
“ASP.NET MVC enables you to build Model View Controller (MVC) applications by using the ASP.NET framework. ASP.NET MVC is an alternative, not a replacement, for ASP.NET Web Forms that offers the following benefits:”
From ASP.Net MVC WebSite
Planning is a critical phase of application development. Without proper planning and defining of goals and features “scope creep” can come in and drive your project off course. Also, if planning is not done up front, and done correctly, you can find yourself with a mess that is hard to modify and/or maintain over time.
We are only going to take a moment to define some features for our application since it will be pretty basic for this tutorial.
So our application will cover 3 main areas; Milestones, tasks, and to do items.
The schema of your database is like the foundation of a house. If built correctly, the house will be solid and even though you may do renovations, even extensive ones, your foundation will continue to support your house. In the same respect if you get the foundation wrong your house might just collapse under its own weight and making changes down the road might just do it in.
In the same way, the stability of your application depends on it’s foundation, your database. We are going to look at the tables that will support our application.
The Milestones table:
We already said that we want milestones to manage deadlines and tell how well we are doing at meeting those deadlines. Obviously we are going to keep this pretty basic, but we have a name and description for the milestone but also we are going to define the date the milestone was created, the deadline when it needs to done, and then we will keep track of the data it was actually completed whether that is sooner or later than the deadline to gives an idea about our performance.
The Tasks table:
This table defines our tasks. Basically a task represents something that we want to get done and contains a bunch of smaller to do items. This is pretty basic. Just an id, name, and description.
An example of a task might be to clean up your yard. This task would involve a number of smaller items to complete to clean the entire yard. We’ll take a look at some of those to do items when we get to that table.
The TodoItems table:
Using our example of cleaning up your yard as a task there would be several todo items involved in completing that task. For example some todo items would be: mow the grass, rake the leaves, trim the trees and bushes, etc.
Our to do items have an id, name, description, a flag indicating whether or not it is complete, and a task id to tie it to the task.
The MilestoneTasks table:
I could have added a MilestoneId to the Tasks table but attaching tasks to milestones is going to be optional in our applications meaning we may want to define some tasks that we don’t want to be on any milestones. Some people feel it is acceptable to have a NULL foreign key while others prefer to use another table to keep their implementation “pure”. It is up to you which you want to use. Both ways will work.
A real world example of this might be tasks that you need to assign to team members but don’t want to show up in any of the milestones that the client see.
This table allows tasks to be tied to milestones and has the flexibility to allow tasks to be assigned to many milestones.
So at this point we have established what MVC and ASP.Net MVC are, what we want our application to accomplish, and a solid database schema that will support our application and be flexible if we need to make changes in the future.
In the next article we’ll look at setting up out ASP.Net MVC application in Visual Studio and look at the Model portion of our application.
The author is Justin Bezanson from GeekDaily.
Tags :ASP.NET MVCControllerModelMVC frameworkSQLViewWhat is MVC
Copyright © 2012 Dev102.com
Breeze : Designed by Amit Raz and Nitzan Kupererd