private static void SeedRoleWorker(IdentityContext context) { if (context.RoleWorker.Any()) { return; // DB has been seeded } context.RoleWorker.AddRange( new RoleWorker { Title = "Camarografo", Level = Level.Basico }, new RoleWorker { Title = "Grabacion", Level = Level.Avanzado }, new RoleWorker { Title = "Sonidista", Level = Level.Basico }, new RoleWorker { Title = "Fotografo", Level = Level.Avanzado } ); context.SaveChanges(); }
private static void SeedUsers(UserManager <ApplicationUser> userManager, IdentityContext context) { // Crea el primer y único administrador si no existe. Primero crea un usuario y luego se asigna el rol de adminstrador. if (userManager.FindByNameAsync(IdentityData.AdminUserName).Result == null) { Admin user = new Admin { Name = IdentityData.AdminName, UserName = IdentityData.AdminUserName, Email = IdentityData.AdminMail, DOB = IdentityData.AdminDOB }; // Es necesario tener acceso a RoleManager para poder buscar el rol de este usuario; se asigna aquí para poder // buscar por rol después cuando no hay acceso a RoleManager. user.AssignRole(userManager, IdentityData.AdminRoleName); IdentityResult result = userManager.CreateAsync(user, IdentityData.AdminPassword).Result; if (result.Succeeded) { IdentityResult addRoleResult = userManager.AddToRoleAsync(user, IdentityData.AdminRoleName).Result; if (!addRoleResult.Succeeded) { throw new InvalidOperationException( $"Unexpected error ocurred adding role '{IdentityData.AdminRoleName}' to user '{IdentityData.AdminName}'."); } } else { throw new InvalidOperationException($"Unexpected error ocurred creating user '{IdentityData.AdminName}'."); } context.Admin.AddRange(user); } }
public RegisterModel( UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, ILogger <RegisterModel> logger, IEmailSender emailSender, IdentityContext context) { _context = context; _userManager = userManager; _signInManager = signInManager; _logger = logger; _emailSender = emailSender; }
/// <summary> /// Crea los usuarios y roles necesarios para el funcionamiento de la aplicación si ya no existente. /// </summary> /// <param name="serviceProvider">El <see cref="IServiceProvider"/> al que se han injectado previamente un /// <see cref="UserManager<T>"/> y un <see cref="RoleManager<T>"/>.</param> public static void Initialize(IServiceProvider serviceProvider) { var userManager = serviceProvider.GetRequiredService <UserManager <ApplicationUser> >(); var roleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >(); SeedRoles(roleManager); using (var context = new IdentityContext( serviceProvider.GetRequiredService < DbContextOptions <IdentityContext> >())) { SeedRoleWorker(context); SeedUsers(userManager, context); } }
public ProfileModel(Ignis.Areas.Identity.Data.IdentityContext context) { _context = context; }
public IndexModel(Ignis.Areas.Identity.Data.IdentityContext context) { _context = context; }
public CreateByHourModel(Ignis.Areas.Identity.Data.IdentityContext context) { _context = context; }
public DeleteModel(Ignis.Areas.Identity.Data.IdentityContext context) { _context = context; }
public AssignModel(Ignis.Areas.Identity.Data.IdentityContext context) { _context = context; }
public RespondModel(Ignis.Areas.Identity.Data.IdentityContext context) { _context = context; }