public ActionResult EditUserRoles(UserViewModel userInfo) { var app = userInfo.Applications; var roles = new Dictionary <string, List <Role> >(); var Roles = new List <Role>(); //var user = _userService.FindBy(u=>u.UserName == userInfo.UserName).SingleOrDefault(); List <Application> originalApps = _userService.GetUserPermissions(userInfo.UserName); var user = _userService.GetUserDetail(userInfo.UserName); //user.DefaultHub = userInfo.DefaultHub; _userService.UpdateUser(user); using (var e1 = app.GetEnumerator()) using (var e2 = originalApps.GetEnumerator()) { while (e1.MoveNext() && e2.MoveNext()) { var item1 = e1.Current; var item2 = e2.Current; } } foreach (var application in app) { foreach (var role in application.Roles) { if (role.IsChecked) { _userService.AddRole(userInfo.UserName, application.ApplicationName, role.RoleName); } else if (!role.IsChecked) { var isRoleAuthorized = false; foreach (var originalApp in originalApps) { if (originalApp.ApplicationName == application.ApplicationName) { foreach (var originalRole in originalApp.Roles) { if (originalRole.RoleName == role.RoleName) { if (originalRole.IsChecked) { isRoleAuthorized = true; } } } } } if (isRoleAuthorized) { _userService.RemoveRole(userInfo.UserName, application.ApplicationName, role.RoleName); } } } //if (Roles.Count > 0) // roles.Add(application.ApplicationName, Roles); } return(RedirectToAction("Index")); //var user = new UserProfile(); //var model = new UserViewModel(); //model.UserName = userInfo.UserName; //List<Application> Applications = userService.GetUserPermissions(userInfo.UserName); //model.Applications = Applications; //return View(model); }