Код кажется мне правильным, я здесь что -то не хватает? /> accountcontroller < /strong> < /p>
Код: Выделить всё
private AppIdentityDbContext context;
public AccountController(AppIdentityDbContext _context)
{
context = _context;
}
public IActionResult Index()
{
var usersWithRoles = (from user in context.Users
select new
{
Username = user.UserName,
Email = user.Email,
RoleNames = (from userRole in user.Roles
join role in context.Roles on userRole.RoleId
equals role.Id
select role.Name).ToList()
}).ToList().Select(p => new UsersViewModel()
{
Username = p.Username,
Email = p.Email,
Role = string.Join(",", p.RoleNames)
});
return View(usersWithRoles);
}
Код: Выделить всё
public class UsersViewModel
{
public string Username { get; set; }
public string Email { get; set; }
public string Role { get; set; }
}
Код: Выделить всё
public class ApplicationUser : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
Код: Выделить всё
public class AppIdentityDbContext : IdentityDbContext
{
public AppIdentityDbContext(DbContextOptions options)
: base(options) { }
}
Код: Выделить всё
public class AppDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(
"Server=(localdb)\\MSSQLLocalDB;Database=Local;MultipleActiveResultSets=true");
}
Подробнее здесь: https://stackoverflow.com/questions/655 ... p-net-core