ASP MVC CRUD Using JQuery Ajax and Entity Framework Part 2 (Creating The Repository, Service, and MVC Controller)


Hey guys, sorry for the lateness since i have been implementing new PHP Framework for 3 weeks. Next time i’ll explain about that PHP Framework 😀 . Now lets continue to create CRUD using Jquery Ajax and Entity Framework. After we have data table User in our database that i have explained in the First Part, now we are going to create Repository layer, Service layer and Presentation Layer. But this time i’ll only explain MVC Controller for presentation layer.

Repository is the layer to do data transaction. This time, i’m using Repository Pattern. First we need to create IGenericRepository :

Why we need to create that interface? Because those methods are common function in all data transactions. So we don’t need to write those method again, it will be handled by inheritance.

Then we create Repository Interface for User Repository that’s called IUserRepository inherit by IGenericRepository :

After we created those interfaces we need to implement those interfaces into classes. Now create UserRepository class that implement IUserRepository :

You can generate the method of interface that you implement by using right click then click Implement Interface. Then fill the method with codes below.

Well, Repository layer is done. Now lets create Service Layer. Service Layer is a place to do validation or implementation of your business process. Since this time we are not talking about validation, lets skip about validation, i’ll talk about this later on.

As usual, lets create the Interface that’s called IUserService :

Then we need to implement that interface, lets create UserService class :

Ahaa.. Repository Layer and Service Layer are done. Now lets create MVC Controller to utilize the Service and Repository, later we’ll test it using Postman Rest Client to see the Json Result.

Now lets create UserController :

After the controller is created. Now we can test it using Postman Rest Client. But only the JsonResult method that we can test since some of methods are using ActionResult to do partial page rendering that will be utilized by Ajax later on the next part.
Test Create Method :



Test Edit Method :



Test Delete Method :



Congratulation your Repository, Service, and Controller have created. Now you are having the Backend Service to continue creating ASP MVC CRUD Using Ajax, Entity Framework and Bootstrap. Please waiting for the next part, i’ll write it soon.

FatkhanFauzi About FatkhanFauzi

A passionate software engineer who wants to share anything that he learns and some of his life experiences. Want to know more about him? see Fatkhan Fauzi Profile


So, what do you think ?

Leave a Reply

%d bloggers like this: