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); }
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); }
public async Task <IActionResult> AddUserToRole(AddUserToRoleInputModel model) { await this.userService.AddUserToRole(model); return(this.RedirectToAction("AllUsers")); }
public async Task AddUserToRole(AddUserToRoleInputModel model) { var user = await this.userManager.FindByIdAsync(model.UserId); await this.userManager.AddToRoleAsync(user, model.RoleName); }