public ActionResult Asignando(AsignarUserModel model) { var roles = context.AspNetRoles.ToList(); List <string> roleslistado = new List <string>(); string rol = ""; foreach (var item in roles) { if (item.Id != model.IdRol) { roleslistado.Add(item.Name); } else { rol = item.Name; } } String[] rollistado = roleslistado.ToArray(); var roleresult = UserManager.RemoveFromRoles(model.Id, rollistado); var roleresults = UserManager.AddToRole(model.Id, rol); return(RedirectToAction("Asignar", "Roles")); }
//[Authorize(Roles = "Admin")] public ActionResult Asignar() { var model = new AsignarUserModel(); var usuarios = context.AspNetUsers.ToList(); var roles = context.AspNetRoles.ToList(); ViewBag.listRoles = roles; foreach (var item in usuarios) { var rol = UserManager.GetRoles(item.Id); var temp = new AsignarUserModel() { Id = item.Id, Name = item.UserName, NameRol = rol.FirstOrDefault(), }; model.Usuarios.Add(temp); } return(View(model)); }
//[Authorize(Roles = "Admin")] public async Task <ActionResult> Resetear(AsignarUserModel model) { Session["Username"] = context.AspNetUsers.FirstOrDefault(x => x.Id == model.Id).UserName; string code = await UserManager.GeneratePasswordResetTokenAsync(model.Id); return(RedirectToAction("ResetPassword", "Account", new { userId = model.Id, code = code })); }