Esempio n. 1
0
        public static ClinicaUserManager Create(
            IdentityFactoryOptions <ClinicaUserManager> options,
            IOwinContext context)
        {
            ClinicaIdentityDbContext dbContext = context.Get <ClinicaIdentityDbContext>();
            ClinicaUserManager       manager   =
                new ClinicaUserManager(new UserStore <ClinicaUser>(dbContext));

            return(manager);
        }
Esempio n. 2
0
        protected override void Seed(ClinicaIdentityDbContext context)
        {
            ClinicaUserManager userMgr =
                new ClinicaUserManager(new UserStore <ClinicaUser>(context));
            ClinicaRoleManager roleMgr =
                new ClinicaRoleManager(new RoleStore <ClinicaRole>(context));

            string roleName = "Administrators";
            string userName = "******";
            string password = "******";
            string email    = "*****@*****.**";

            if (!roleMgr.RoleExists(roleName))
            {
                roleMgr.Create(new ClinicaRole(roleName));
            }

            ClinicaUser user = userMgr.FindByName(userName);

            if (user == null)
            {
                userMgr.Create(new ClinicaUser
                {
                    UserName = userName,
                    Email    = email
                }, password);
                user = userMgr.FindByName(userName);
            }

            if (!userMgr.IsInRole(user.Id, roleName))
            {
                userMgr.AddToRole(user.Id, roleName);
            }

            base.Seed(context);
        }