ASP.NET MVC5 How can I create a CRUD for the AspNetUsers table

2

How can I create a CRUD for the AspNetUsers table, creating a MVC 5 controller with views using Entity Framework

This is the structure of the table: AspNetUsers

This is the Model: IdentityModels

namespace Portal.Models
{

    public class ApplicationUser : IdentityUser
    {
        public string Nombre { get; set; }
        public string Apellido { get; set; }
        public string Departamento { get; set; }

    }

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("DefaultConnection")
        {
        }
    }
}
    
asked by AbregoW 04.05.2016 в 02:03
source

2 answers

1

The class UserManager

is used to work with the entity IdentityUser

Introduction to ASP.NET Identity

You'll see in the example how he uses

UserManager.CreateAsync()

Cutting Edge: A First Look at ASP.NET Identity

In your case you could use the same UserManager to operate with the entity ApplicationUser that you are extending

    
answered by 05.05.2016 в 17:49
1

You can create a CRUD or Scaffolding of the entity ApplicationUser in the same way you would with any other entity. But, you have to be very careful with what you do because, as it says Leandro Tuttini in your answer, to work with the entity IdentityUser the class UserManager is used (both of Microsoft ASP.NET Identity 2.0 )

The first step would be to add the new driver with the "MVC 5 Controller with views using Entity Framework" option

Then you would select the entity ApplicationUser and DbContext

Finally you should make a couple of changes to the code that you have automatically generated

  • In the ApplicationDbContext you must remove the ApplicationUsers property that the process has added

  • In ApplicationUsersController you must replace the use of property ApplicationUsers with Users

Like, I said at the beginning, you should be very careful with what you do in this way because you could skip certain things that are responsible for the UserManager that could give you problems. I would recommend that all modification operations be modified to make them through it.

    
answered by 07.05.2016 в 00:32