Don't directly call your database in controller.
In your Asp.net MVC Application, you should not place your database logic inside your controller actions. Mixing your database and controller logic makes your application more difficult to maintain over time. It is recommended that you place your database logic in separate repository layer.
Don't directly call your repository in controller.
You should create another separate layer called service layer or business logic layer, and put your application business logic. roles and validations. Service layer communicates with the repository layer, process the data into information and pass it the controller.
Don't coupled your service layer with controller.
You should isolate your service layer with controller. Service layer must be in-depended, means it should not depended on the plate-form depended objects. So any application can use it without worrying about frame-work version and plate-form.
for example: The service layer should be able to use in WinForms , WebForms , WPF or Asp.net MVC Applications.
Don't put your UI Logic in controller.
UI may have some kind of logic, such as, display the user panel if the user is logged In, show/hide buttons, show the publish button if the publisher is logged in and so on. This logic may have several conditions, functions and properties, We should avoid to put the UI logic directly in our controller because controller is not responsible for handling the logic, but the application flow.
Mixing your application flow and UI/Business logic makes more difficult to maintain your application. We should separate our UI Logic in form of view models, and view models should be called by controller.
Controller is responsible for taking the input from user and pass it to the view models, view model take the input from controller, apply some UI logic if needed, and pass it to he service layer, service layer process it and pass it to repository, and repository is responsible for manipulate the database.
