public ActionResult AddUserConfirm(Guid UserGroupID, Guid UserID) { UserGroup userGroupInsert = new UserGroup(); if (userGroupInsert.AddUserToRole(UserGroupID, UserID)) { return(RedirectToAction("ManageUser", new { id = UserGroupID })); } List <IdentityUser> userList = db.Users.ToList <IdentityUser>(); IdentityRole identityRole = db.Roles.Find(UserGroupID.ToString()); UserGroup userGroup = new UserGroup(); userGroup.UserGroupID = new Guid(identityRole.Id); userGroup.UserGroupName = identityRole.Name; ViewBag.UserGroup = userGroup; List <GroupUser> reverseGroupUserList = new List <GroupUser>(); foreach (IdentityUser identityUser in userList) { bool bFound = false; string UserRoleID = ""; foreach (IdentityUserRole identityUserRole in identityRole.Users) { if (identityUser.Id == identityUserRole.UserId) { UserRoleID = identityUserRole.RoleId; bFound = true; } } if (!bFound) { GroupUser groupUser = new GroupUser(); groupUser.UserID = new Guid(identityUser.Id); groupUser.UserName = identityUser.UserName; groupUser.Email = identityUser.Email; reverseGroupUserList.Add(groupUser); } } return(RedirectToAction("AddUser", new { UserGroupID = UserGroupID })); }