VS2015 - MVC - Getting a list of users for Admin Panel
-
Hello! I have created a project intended to get a better understanding of how to create an admin panel for users and seed data. It seems to me that seeding is now working as intended, but the admin panel for users is a bit more complicated than I thought it would be. Let's start by saying I have already looked at this tutorial on the topic but I find it's geared to such a different workflow than mine that trying to adapt it without having a firm grasp on the topic would be a lot more work than having something basic working for my own. The main issues I have with that article is that it is entirely based on the idea that users cannot register from the outside(which I instead want) and it is a preparation for another article to manage user groups (that I do not need at the moment). From Googling, I realised that I need a couple of ViewModels, so I created them:
public class UserViewModel
{
[Required]
[Display(Name = "Email")]
[EmailAddress]
public string Email { get; set; }\[Required\] \[Display(Name = "Enabled")\] public Boolean Enabled {get; set; } \[Required\] \[Display(Name ="Active")\] public Boolean Active { get; set; } \[Required\] \[Display(Name = "Lockout date and time")\] public DateTime? LockoutEndDateUtc { get; set; } \[Required\] \[Display(Name ="Lockout enabled")\] public Boolean LockoutEnabled { get; set; } } public class UserListViewModel { private ICollection<UserViewModel> \_UserList = new List<UserViewModel>(); public UserListViewModel( ApplicationDbContext ctx) { UserViewModel User; foreach (var user in ctx.Users) { User = new UserViewModel(); User.Email = user.Email; User.Active = user.Active; User.Enabled = user.Enabled; User.LockoutEnabled = user.LockoutEnabled; User.LockoutEndDateUtc = user.LockoutEndDateUtc; } }
Trying to create a controller, however, resulted in VS kicking and screaming that there is no key. Googling again, it appears that VS thinks I am creating new database entities(something that I am not trying to do, promise!!!). My understanding