Esempio n. 1
0
 public AdminController(ILogService logService, IVideoAttributesService videoAttributesService, IMapper mapper)
     : base(logService, mapper)
 {
     _context                = new FluxyContext();
     _userManager            = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(_context));
     _videoAttributesService = videoAttributesService;
     _mapper = mapper;
 }
 public UserMangementController(IUserProfileService userProfileService, ILogService logService, IMapper mapper)
     : base(logService, mapper)
 {
     _context            = new FluxyContext();
     _userProfileService = userProfileService;
     _mapper             = mapper;
     _roleManager        = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(_context));
     _userManager        = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(_context));
 }
Esempio n. 3
0
        private void CreateRolesandUsers()
        {
            FluxyContext context = new FluxyContext();

            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));


            // In Startup iam creating first Admin Role and creating a default Admin User
            if (!roleManager.RoleExists("Admin"))
            {
                // first we create Admin rool
                var role = new IdentityRole
                {
                    Name = "Admin"
                };
                roleManager.Create(role);
            }

            if (!roleManager.RoleExists("Users"))
            {
                var role = new IdentityRole
                {
                    Name = "Users"
                };
                roleManager.Create(role);
            }
            var adminUser = UserManager.FindByName("Rajadityan");

            if (adminUser == null)
            {
                var user = new ApplicationUser
                {
                    UserName       = "******",
                    Email          = "*****@*****.**",
                    EmailConfirmed = true
                };
                string userPassword = "******";
                var    chkUser      = UserManager.Create(user, userPassword);
                //Add default User to Role Admin
                if (chkUser.Succeeded)
                {
                    var result1 = UserManager.AddToRole(user.Id, "Admin");
                }
            }
        }