public Startup(IConfiguration configuration) { using (var client = new ApiDbContext()) { client.Database.EnsureCreated(); } using (var client = new ApplicationUserContext()) { client.Database.EnsureCreated(); } Configuration = configuration; }
public static async Task Initialize(IServiceProvider serviceProvider, string testUserPw) { using (var context = new ApplicationUserContext( serviceProvider.GetRequiredService <DbContextOptions <ApplicationUserContext> >())) { var adminID = await EnsureUser(serviceProvider, testUserPw, "*****@*****.**"); // creates user if one is not already created await EnsureRole(serviceProvider, adminID, Constants.AdminRole); // checks that newly created user has specifed role (admin) await AddRole(serviceProvider, Constants.DefaultRole); await AddRole(serviceProvider, Constants.EditorRole); } }
private void createDefaultRolesAndUsers() { ApplicationUserContext context = new ApplicationUserContext(); var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); var RoleManager = new RoleManager <ApplicationRole>(new RoleStore <ApplicationRole>(context)); if (!RoleManager.RoleExists("Admin")) { // create Admin role var role = new ApplicationRole() { Name = "Admin" }; RoleManager.Create(role); // create default user and make him the Admin var user = new ApplicationUser() { UserName = "******", Email = "*****@*****.**" }; var chkUser = UserManager.Create(user, "1234Share"); if (chkUser.Succeeded) { var result1 = UserManager.AddToRole(user.Id, "Admin"); } } if (!RoleManager.RoleExists("User")) { var role = new ApplicationRole(); role.Name = "User"; RoleManager.Create(role); } }
public ApplicationUserComponent(ApplicationUserContext cxt) { this._ctx = cxt; }
public CreateModel(ApplicationUserContext context) { _context = context; }
private void DisplayUsersBelongingToRole() { // Get the selected role string selectedRoleName = RoleList.SelectedValue; // Get the list of usernames that belong to the role var db = new ApplicationUserContext(); var rm = new RoleManager(); var selectedRole = rm.FindByName(selectedRoleName); var usersBelongingToRole = db.Users .Where(u => u.Roles.Any(r => r.RoleId == selectedRole.Id)) .ToList(); // Bind the list of users to the GridView RolesUserList.DataSource = usersBelongingToRole; RolesUserList.DataMember = "UserName"; RolesUserList.DataBind(); }
private void BindUsersToUserList() { // Get all of the user accounts var db = new ApplicationUserContext(); var users = db.Users.ToList(); UserList.DataSource = users; UserList.DataMember = "UserName"; UserList.DataBind(); }
public RegisterModel(ApplicationUserContext context) { _context = context; }
public ApplicationUsersController(ApplicationUserContext context, UserManager <ApplicationUser> userManager) { _context = context; _userManager = userManager; }
public LoginModel(ApplicationUserContext context) { _context = context; }
private void BindRolestoGridView() { var db = new ApplicationUserContext(); RolesGrid.DataSource = db.Roles.ToList().Select(r => r.Name); RolesGrid.DataBind(); }
public HomeController(ApplicationUserContext context) { _context = context; }
public ApplicationUserRepository(IUnitOfWork<ApplicationUserContext> uow) { _context = uow.Context; this._dbSet = _context.Set<ApplicationUser>(); _uow = uow; }
public UserManagerComponent(ApplicationUserContext ctx) { this._cxt = ctx; }