mirror of
https://github.com/lempamo/Project-Unite.git
synced 2025-01-22 11:21:47 -05:00
addusertorole
This commit is contained in:
parent
774b319a47
commit
1b15a34906
1 changed files with 36 additions and 0 deletions
|
@ -27,6 +27,42 @@ public ActionResult Index(string id = "home")
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ActionResult AddUserToRole(string id)
|
||||||
|
{
|
||||||
|
var model = new AddUserToRoleViewModel();
|
||||||
|
model.Roles = new List<SelectListItem>();
|
||||||
|
var db = new ApplicationDbContext();
|
||||||
|
foreach(var r in db.Roles.ToArray())
|
||||||
|
{
|
||||||
|
var converted = r as Role;
|
||||||
|
model.Roles.Add(new SelectListItem
|
||||||
|
{
|
||||||
|
Text = converted.Name,
|
||||||
|
Value = converted.Id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
model.Users = new List<SelectListItem>();
|
||||||
|
foreach(var u in db.Users.OrderBy(x => x.DisplayName).ToArray())
|
||||||
|
{
|
||||||
|
model.Users.Add(new SelectListItem
|
||||||
|
{
|
||||||
|
Text = u.DisplayName,
|
||||||
|
Value = u.Id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
model.RoleId = id;
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public ActionResult AddUserToRole(AddUserToRoleViewModel model)
|
||||||
|
{
|
||||||
|
var usermanager = HttpContext.GetOwinContext().Get<ApplicationUserManager>();
|
||||||
|
usermanager.AddToRole(model.Username, model.RoleId);
|
||||||
|
return Index("roles");
|
||||||
|
}
|
||||||
|
|
||||||
public ActionResult RoleDetails(string id)
|
public ActionResult RoleDetails(string id)
|
||||||
{
|
{
|
||||||
var db = new ApplicationDbContext();
|
var db = new ApplicationDbContext();
|
||||||
|
|
Loading…
Reference in a new issue