Exemplo n.º 1
0
 public ActionResult UserRoles(SelectUserRolesViewModel model)
 {
     if (ModelState.IsValid)
     {
         var idManager = new IdentityManager();
         var Db = new ApplicationDbContext();
         var account = Db.Users.First(u => u.UserName == model.UserName);
         idManager.ClearUserRoles(account.Id);
         foreach (var role in model.Roles)
         {
             if (role.Selected)
             {
                 idManager.AddUserToRole(account.Id, role.RoleName);
             }
         }
         return RedirectToAction("index");
     }
     return View();
 }
Exemplo n.º 2
0
 /// <summary>
 /// Returns a view showing the roles for a selected user.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <returns></returns>
 public ActionResult UserRoles(string id)
 {
     if (!string.IsNullOrEmpty(id))
     {
         var Db = new ApplicationDbContext();
         var account = Db.Users.First(u => u.UserName == id);
         var model = new SelectUserRolesViewModel(account);
         return View(model);
     }
     else
     {
         return RedirectToAction("Index");
     }
 }