// Enable initialization with an instance of ApplicationUser:
        public SelectUsersInRoleViewModel(IUser loggedinuser, ApplicationRole role, string searchkey)
            : this()
        {
            this.RoleName = role.Name;
            var Db = new ApplicationDbContext(loggedinuser);

            // Add all available users to the list of EditorViewModels:
            this.UserCount = Db.Users.Count();
            var allUsers = Db.Users.OrderBy(p => p.UserName).Take(50).ToList();//search

            if (!string.IsNullOrEmpty(searchkey))
            {
                this.UserCount = Db.Users.Where(p => p.UserName.ToUpper().Contains(searchkey.ToUpper()) || p.FirstName.ToUpper().Contains(searchkey.ToUpper()) || p.LastName.ToUpper().Contains(searchkey.ToUpper())).Count();
                allUsers       = Db.Users.Where(p => p.UserName.ToUpper().Contains(searchkey.ToUpper()) || p.FirstName.ToUpper().Contains(searchkey.ToUpper()) || p.LastName.ToUpper().Contains(searchkey.ToUpper())).OrderBy(p => p.UserName).Take(50).ToList();
            }

            foreach (var user in allUsers)
            {
                // An EditorViewModel will be used by Editor Template:
                var rvm = new SelectUserEditorViewModel(user);
                this.Users.Add(rvm);
            }
            // Set the Selected property to true for those roles for
            // which the current user is a member:
            foreach (var user in allUsers)
            {
                var checkUsersInRole = this.Users.Find(r => r.UserName == user.UserName);
                var roleIds          = user.Roles.Select(r => r.RoleId);
                checkUsersInRole.Selected = Db.Roles.Where(r => roleIds.Contains(r.Id))
                                            .Any(r => r.Name == RoleName);
            }
        }
        // Enable initialization with an instance of ApplicationUser:
        public SelectUsersInRoleViewModel(IUser loggedinuser, ApplicationRole role)
            : this()
        {
            this.RoleName = role.Name;
            var Db = new ApplicationDbContext(loggedinuser);
            // Add all available users to the list of EditorViewModels:
            var allUsers = Db.Users.ToList();

            foreach (var user in allUsers)
            {
                // An EditorViewModel will be used by Editor Template:
                var rvm = new SelectUserEditorViewModel(user);
                this.Users.Add(rvm);
            }
            // Set the Selected property to true for those roles for
            // which the current user is a member:
            foreach (var user in allUsers)
            {
                var checkUsersInRole = this.Users.Find(r => r.UserName == user.UserName);
                var roleIds          = user.Roles.Select(r => r.RoleId);
                checkUsersInRole.Selected = Db.Roles.Where(r => roleIds.Contains(r.Id))
                                            .Any(r => r.Name == RoleName);
            }
        }