First, I'm assuming the organization for ASP.NET Identity, so the answer does not turn up a textural wall.
Assuming the following scenario:
- Controller for user (UserController);
- ViewModel for user actions;
- Class representing the user entity;
- Class representing the user repository;
- Some User Views have images;
- Some User Views have specific scripts and css's.
How can I organize the above scenario?
In ASP.NET Identity this is already organized for you as follows:
-
Controller for User:
Controllers/AccountController
;
-
ViewModels for User Actions:
Models/AccountViewModel
;
- Class representing the User entity:
ApplicationUser
, in Models/IdentityModels
. This does not mean that additional entities should be in the IdentityModels
source. It is best to leave one font per class;
- Class representing the User repository: If you are using the Entity Framework, the Entity Framework is the repository not only of User, but of all system entities . In an ASP.NET MVC5 application, it is within
ApplicationDbContext
( Models/IdentityModels
), derived from IdentityDbContext
, which contains IDbSet<TUser> Users
. This Users
is the repository;
- Some user views have images: You can save the user's images to the database in the
Content/Images
directory or use Gravatar .
- Some User Views have specific scripts and CSS: You would have to mount
@section
s dynamically. Usually the project is configured with two: scripts
and views
. See your _Layout.cshtml
file to see where those sections will be written. It's not worth putting this here. This part deserves a separate question.
Where should I write the code for all ViewModels? Should these be in the same location as the user entity?
In a directory ViewModels
, separated from other directories ( Models
, Controller
, Views
, ...).
And the images of a specific View should be grouped in the Content folder?
Yes. I usually use Content\Images\MinhaView\
. You can create as many subdirectories as you want from there. Just do not forget to set a index.html
file for each level, to avoid problems with the publication (if the directories are empty, Web Deploy does not create the directories at the destination of the publication).