I have 3 types of user in my application(in asp.net mvc-5): Admin, Doctor and User. In Models folder I’ve created 3 other folder, one for each type of user. Should I create a single ViewModel, suppose DoctorViewModel which will carry all information about doctor? Or should I create DoctorLoginViewModel and DoctorRegistractionViewModel and so on?
N.B: I have separate tables in database for credentials(email and pass) and for personal Information(age, dob, gender etc).
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You can simply use one model User which will carry out all common properties with those 3 types.
public class User
{
public string Name { get; set; }
public string LastName { get; set; }
public UseType Type { get; set; }
}
public enum UserType
{
User = 1,
Doctor = 2,
Admin = 3
}
And then if you want have separate views for each of the users, then you can create DoctorViewModel or UserViewModel as needed.
I would suggest you to read about Role based auhtorization in asp.net mvc.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0