Example #1
0
        public IHttpActionResult MakeUserAdmin(string username)
        {
            var user = this.Data.Users.All().ToList().FirstOrDefault(u => u.UserName == username);

            var um = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));

            string adminCheck = um.GetRoles(user.Id).FirstOrDefault(a => a.Contains("AppAdmin"));

            if (adminCheck != string.Empty)
            {
                return this.BadRequest(string.Format("user {0} is allready admin", user.UserName));
            }

            um.AddToRolesAsync(user.Id, "AppAdmin");

            this.Data.SaveChanges();

            return this.Ok(string.Format("user: {0} is admin", user.UserName));

        }
Example #2
0
 private static async Task CreateUserSync(UserManager<ApplicationUser> userManager, UserTemplate userTemplate, ApplicationUser user)
 {
     await userManager.CreateAsync(user, userTemplate.Password);
     await userManager.AddToRolesAsync(user, userTemplate.Roles);
 }
        private static void AddUsersToRoles(UserManager<ApplicationUser> users, RoleManager<ApplicationRole> roleManager)
        {
            var admin = users.FindByEmailAsync("[email protected]").Result;
            var esthetician = users.FindByEmailAsync("[email protected]").Result;

            Task.FromResult(users.AddToRolesAsync(admin, new[] { "Admin", "Esthetician" }).Result);
            Task.FromResult(users.AddToRoleAsync(esthetician, "Esthetician").Result);
        }