ASP.NET MVC Example – Part 2

I hope you read part -1 of this example and understand a basic and high level of over view of MVC architecture, in this part I will be talking above the Model (Business logic Layer)

Part – 1: Creating basic MVC project

Part – 2: Creating Business Logic layer

Part – 3: Interacting with Model

This is general concept not specific to MVC or any architecture; I am going to create a class which handles all the manipulation of the Student Database.

Create a new database in SQL Server and name it as Students, and Create a Table Student with following fields.

StudentID – Int (Identity on)

StudentName – nvarchar(50)

StudentAddress – nvarchar(50)

StudentCity – nvarchar(50)

StudentClass – nvarchar(50)

Once you have done with creating a sample students database, now open our StudnetMVCExample project and right click on the Model folder in solution explorer and Add New Item and select a class file, and name it as StudentsMiddleware click Ok.

Now create a getStudentDetails function as you see in below screen shot, and also don’t forget to declare a private variable strConnectionString

getstudent

 

Add a function to get all students

 

getAllStudent

 

Add a function to Insert Student Details

insertstudent

Add a function to Update Student Details

updatestudent

As we are dealing with student, it is better and simple to have student class which will hold details of a single Student, create a student class in same file after StudentsMiddleWare class like shown in below Screen shot

studentclass

Now we are ready with our middle ware logic, so we can continue with our MVC web application.

Very soon I will be posting next part of this example in which I will be explaining how to interact with Model in MVC web application.

Happy Coding

Regards,

Satish.

Leave a Reply

Powered by WP Hashcash