Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. VS2015 - MVC - Getting a list of users for Admin Panel

VS2015 - MVC - Getting a list of users for Admin Panel

Scheduled Pinned Locked Moved ASP.NET
asp-nettutorialdatabasevisual-studiocom
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DeerBear
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups