public ActionResult AddUserToRole(AddToRoleModel model) { var user = UserManager.FindByName(model.UserName); UserManager.AddToRole(user.Id, model.SelectedRole); return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> AddToRole([FromBody] AddToRoleModel model) { var user = await userManager.FindByNameAsync(model.UserName); if (user == null) { return(Ok(new ServiceResult { Status = "Error", Message = "User is not exists" })); } var roleExists = await roleManager.RoleExistsAsync(model.RoleName); if (!roleExists) { return(Ok(new ServiceResult { Status = "Error", Message = "Role is not exists" })); } var result = await userManager.AddToRoleAsync(user, model.RoleName); return(Ok(new ServiceResult { Status = "Success", Message = "User is added to specified role successfully" })); }
public ActionResult AddToRole(AddToRoleModel model) { var korisnik = UserManager.FindByEmail(model.Email); UserManager.AddToRole(korisnik.Id, model.SelectRole); return(RedirectToAction("Index", "Home")); }
public ActionResult AddUserToRole(AddToRoleModel model) { var user = UserManager.FindByEmail(model.Email); UserManager.AddToRole(user.Id, model.Role); return(RedirectToAction("Index", "Albums")); }
public async Task <IActionResult> AddToRole(AddToRoleModel model) { var roleExists = await this.roleManager.RoleExistsAsync(model.Role); var user = await this.userManager.FindByIdAsync(model.UserId); var userExists = user != null; if (!ModelState.IsValid) { return(RedirectToAction(nameof(All))); } if (!roleExists || !userExists) { return(RedirectToAction(nameof(All))); } var result = await userManager.AddToRoleAsync(user, model.Role); if (!result.Succeeded) { TempData.AddErrorMessage($"User {user.UserName} was NOT set to a role of {model.Role}"); return(RedirectToAction(nameof(All))); } TempData.AddSuccessMessage($"User {user.UserName} was set to a role of {model.Role}"); return(RedirectToAction(nameof(All))); }
public async Task <MessageReponse> AddUserToRole(AddToRoleModel model) { var user = await _userManager.FindByNameAsync(model.UserName); if (user == null) { return(new MessageReponse() { Message = "UserName not Found", IsSuccess = false, }); } else { var role = await _roleManager.FindByNameAsync(model.RoleName); if (role == null) { return(new MessageReponse() { Message = "RoleName not Found", IsSuccess = false, }); } else { var userRole = await _userManager.GetRolesAsync(user); bool checkrole = userRole.ToList().Contains(model.RoleName); if (checkrole) { return(new MessageReponse() { Message = "User already belong to role", IsSuccess = false, }); } else { var result = await _userManager.AddToRoleAsync(user, role.Name); if (result.Succeeded) { return(new MessageReponse() { Message = "Added successed", IsSuccess = true, }); } return(new MessageReponse() { Message = "Added Failed", IsSuccess = true, }); } } } }
public ActionResult AddUserToRole() { var model = new AddToRoleModel(); model.roles.Add("Administrator"); model.roles.Add("User"); return(View(model)); }
public ActionResult AdminPanel() { var model = new AddToRoleModel(); model.Roles.Add("Admin"); model.Roles.Add("User"); return(View(model)); }
public async Task <IActionResult> AddUserToRole(AddToRoleModel model) { var userToRole = await _roleService.AddUserToRole(model); if (userToRole == null) { return(BadRequest(userToRole)); } return(Ok(userToRole)); }
public ActionResult AddUserToRole() { var model = new AddToRoleModel(); model.Roles.Add("ADMIN"); model.Roles.Add("EDITOR"); model.Roles.Add("USER"); return(View(model)); }
public async Task <IActionResult> RemoveUserFromRole(AddToRoleModel model) { var remove = await _roleService.RemoveUserFromRole(model); if (remove == null) { return(BadRequest(remove)); } return(Ok(remove)); }
public ActionResult AddUserToRole() { var roleStore = new RoleStore <IdentityRole>(db); var roleMngr = new RoleManager <IdentityRole>(roleStore); var model = new AddToRoleModel(); model.roles = roleMngr.Roles.Select(x => x.Name).ToList(); model.Emails = UserManager.Users.Select(x => x.Email).ToList(); return(View(model)); }
//custom code public ActionResult AddUserToRole() { AddToRoleModel model = new AddToRoleModel(); model.roles = new List <string>() { "Admin", "Editor", "User" }; return(View(model)); }
public ActionResult AddRoleToUser() { AddToRoleModel m = new AddToRoleModel(); m.ulogi = new List <string>() { "Administrator", "Manager", "User" }; return(View(m)); }
public ActionResult AddUserToRole() { var model = new AddToRoleModel(); model.roles = new System.Collections.Generic.List <string>(); model.roles.Add("Administrator"); model.roles.Add("Publisher"); model.roles.Add("User"); return(View(model)); }
public ActionResult AddUserToRole(AddToRoleModel model) { try { var userr = UserManager.FindByEmail(model.Email); UserManager.AddToRole(userr.Id, model.SelectedRole); return(RedirectToAction("Index", "Stores")); } catch (Exception ex) { return(HttpNotFound()); } }
public ActionResult AddUserToRole() { var model = new AddToRoleModel(); // model.roles = UserManager.GetRoles().ToList(); model.roles.Add("Admin"); model.roles.Add("User"); return(View(model)); }
public ActionResult AddUserToRole(AddToRoleModel model) { var user = UserManager.FindByEmail(model.Email); if (user == null) { throw new HttpException(404, "Не постои корисник со следната Е-пошта: " + model.Email); } UserManager.AddToRole(user.Id, model.selectedRole); return(RedirectToAction("Index", "Home")); }
public ActionResult AddUserToRole() { updateCartIcon(); AddToRoleModel model = new AddToRoleModel(); model.roles = new List <string>() { "User", "Publisher", "Admin" }; return(View(model)); }
public ActionResult AddUserToRole() { var users = UserManager.Users.ToList(); users.RemoveAll(u => u.UserName == User.Identity.Name); var model = new AddToRoleModel(); model.Roles = Roles.ListRoles(); model.Users = users; return(View(model)); }
public ActionResult AddUserToRole(AddToRoleModel m) { var mail = m.mail; var user = UserManager.FindByEmail(m.mail); if (user == null) { throw new HttpException(404, "There is no user with this email"); } UserManager.AddToRole(user.Id, m.selected); return(RedirectToAction("Index", "FriendModels")); }
public ActionResult AddUserToRole() { var model = new AddToRoleModel(); model.roles.Add(Roles.Administrator); model.roles.Add(Roles.Moderator); model.roles.Add(Roles.User); model.mails = UserManager.Users.Select(u => u.Email).ToList(); return(View(model)); }
public ActionResult AddUserToRole(AddToRoleModel model) { var email = model.Email; var user = UserManager.FindByEmail(model.Email); if (user == null) { throw new HttpException(404, "There is no user with email: " + model.Email); } UserManager.AddToRole(user.Id, model.selectedRole); return(RedirectToAction("Index", "Home")); }
public ActionResult AddUserToRole(AddToRoleModel model) { var email = model.Email; var user = UserManager.FindByEmail(model.Email); if (user == null) { return(HttpNotFound()); } UserManager.AddToRole(user.Id, model.selectedRole); return(RedirectToAction("Index", "Posts")); }
public ActionResult AddUserToRole(AddToRoleModel model) { try { var user = UserManager.Users.FirstOrDefault(u => u.Email == model.Email); UserManager.AddToRole(user.Id, model.selectedRole); return(RedirectToAction("Index", "Home")); } catch (Exception ex) { return(HttpNotFound()); } }
public ActionResult AddUserToRole(AddToRoleModel model) { try { var user = UserManager.FindByEmail(model.Email); this.UserManager.AddToRoleAsync(user.Id, model.selectedRole); return(RedirectToAction("Index", "Home")); } catch (Exception ex) { return(RedirectToAction("Index", "Home")); } }
public ActionResult AddUserToRole(AddToRoleModel model) { try { var user = UserManager.FindByEmail(model.Email); UserManager.AddToRole(user.Id, model.Role); return(View("AddUserToRole", model)); } catch (Exception ex) { return(HttpNotFound()); } }
public ActionResult AddUserToRole() { var model = new AddToRoleModel(); model.roles.Add("Administrator"); model.roles.Add("User"); foreach (Person p in db.People) { model.emails.Add(p.Email); } return(View(model)); }
public ActionResult AddUserToRole() { AddToRoleModel model = new AddToRoleModel(); User user = new User(); foreach (var u in UserManager.Users) { model.users.Add(u.Email); } model.roles.Add("Admin"); model.roles.Add("Employee"); return(View(model)); }
public ActionResult AddUserToRole() { AddToRoleModel model = new AddToRoleModel(); foreach (var u in UserManager.Users) { model.users.Add(u.Email); } model.roles.Add("Administrator"); model.roles.Add("User"); model.roles.Add("Owner"); return(View(model)); }