예제 #1
0
        public async Task <IActionResult> AddToRole(AddUserToRoleInputModel model)
        {
            var viewModel = this.usersService.GetDataForRoleAdding();

            if (!this.ModelState.IsValid)
            {
                return(this.View(viewModel));
            }

            await this.usersService.AddUserToRole(model);

            return(this.Redirect("/"));
        }
        public async Task AddUserToRole(AddUserToRoleInputModel model)
        {
            var user = await this.userRepository.All().FirstOrDefaultAsync(x => x.UserName == model.Users);

            var isUserInRole = await this.userManager.IsInRoleAsync(user, model.Roles);

            if (isUserInRole)
            {
                return;
            }

            await this.userManager.AddToRoleAsync(user, model.Roles);
        }
예제 #3
0
        public async Task <AddUserToRoleInputModel> GetUserById(string id)
        {
            var result = await this.userManager.FindByIdAsync(id);

            var user = new AddUserToRoleInputModel
            {
                FirstName = result.FirstName,
                LastName  = result.LastName,
                UserId    = result.Id,
                Users     = this.GetAllUsers(),
                Roles     = this.GetAllRoles(),
            };

            return(user);
        }
예제 #4
0
        public async Task <IActionResult> AddUserToRole(AddUserToRoleInputModel model)
        {
            await this.userService.AddUserToRole(model);

            return(this.RedirectToAction("AllUsers"));
        }
예제 #5
0
        public async Task AddUserToRole(AddUserToRoleInputModel model)
        {
            var user = await this.userManager.FindByIdAsync(model.UserId);

            await this.userManager.AddToRoleAsync(user, model.RoleName);
        }