Exemplo n.º 1
0
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);

            if (AbstractService.Context == null)
            {
                AbstractService.Context = new ApplicationDbContext();
            }
            var store = new UserStore <ApplicationUser>(AbstractService.Context);
            var v     = new ApplicationUserManager(store);
            //var v = new ApplicationUserManager((IUserStore<ApplicationUser>)AbstractService.Context.Users);
            var roleService = new RoleService(new Guid());
            //var accntCnt = new AccountController(v,new ApplicationSignInManager(v,null));
            var accountService  = new AccountService(Guid.NewGuid(), v);
            var userRoleService = new UserRoleService(new Guid(), v);

            if (!roleService.Exists("Admin"))
            {
                roleService.CreateRole("Admin");
                var user = new ApplicationUser
                {
                    UserName = "******",
                    Email    = "*****@*****.**"
                };
                //if (GStorage.Data["UserManager"] == null) throw new Exception("USERMANAGER GLOBAL IS NULL");
                var result = v.Create(user, "SATAN@666");
                var urs    = new UserRoleService(new Guid(), v);
                urs.AssignRole(Guid.Parse(user.Id), roleService.GetRoleByName("Admin"));
                AbstractService.Context.SaveChanges();
            }
            //userRoleService.RemoveUnmapped();
        }