コード例 #1
0
 public Startup(IConfiguration configuration)
 {
     using (var client = new ApiDbContext())
     {
         client.Database.EnsureCreated();
     }
     using (var client = new ApplicationUserContext())
     {
         client.Database.EnsureCreated();
     }
     Configuration = configuration;
 }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
ファイル: Startup.cs プロジェクト: toanphan19/kalafina-wiki
        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);
            }
        }
コード例 #4
0
 public ApplicationUserComponent(ApplicationUserContext cxt)
 {
     this._ctx = cxt;
 }
コード例 #5
0
 public CreateModel(ApplicationUserContext context)
 {
     _context = context;
 }
コード例 #6
0
    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();
    }
コード例 #7
0
 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();
 }
コード例 #8
0
 public RegisterModel(ApplicationUserContext context)
 {
     _context = context;
 }
コード例 #9
0
 public ApplicationUsersController(ApplicationUserContext context, UserManager <ApplicationUser> userManager)
 {
     _context     = context;
     _userManager = userManager;
 }
コード例 #10
0
 public LoginModel(ApplicationUserContext context)
 {
     _context = context;
 }
コード例 #11
0
 private void BindRolestoGridView()
 {
     var db = new ApplicationUserContext();
     RolesGrid.DataSource = db.Roles.ToList().Select(r => r.Name);
     RolesGrid.DataBind();
 }
コード例 #12
0
 public HomeController(ApplicationUserContext context)
 {
     _context = context;
 }
コード例 #13
0
 public ApplicationUserRepository(IUnitOfWork<ApplicationUserContext> uow)
 {
     _context = uow.Context;
     this._dbSet = _context.Set<ApplicationUser>();
     _uow = uow;
 }
コード例 #14
0
 public UserManagerComponent(ApplicationUserContext ctx)
 {
     this._cxt = ctx;
 }