// Enable initialization with an instance of ApplicationUser:
        public UserRoleViewModel(AppUser user, string controllername, IQueryable <AppRole> approles)
            : this()
        {
            this.SelectedUserId = user.Id;
            this.ControllerName = controllername;
            foreach (var role in approles)
            {
                // An EditorViewModel will be used by Editor Template:
                var srevm = new SelectRoleEditorViewModel(role);
                this.Roles.Add(srevm);
            }

            foreach (var assignedRole in user.Roles)
            {
                var checkAssignedRole =
                    this.Roles.Find(r => r.ID == assignedRole.RoleId);
                checkAssignedRole.Selected = true;
            }
        }
示例#2
0
        // Enable initialization with an instance of ApplicationUser:
        public UserRoleViewModel(AppUser user, string controllername, IQueryable<AppRole> approles)
            : this()
        {
            this.SelectedUserId = user.Id;
            this.ControllerName = controllername;
            foreach (var role in approles)
            {
                // An EditorViewModel will be used by Editor Template:
                var srevm = new SelectRoleEditorViewModel(role);
                this.Roles.Add(srevm);
            }

            foreach (var assignedRole in user.Roles)
            {
                var checkAssignedRole =
                    this.Roles.Find(r => r.ID == assignedRole.RoleId);
                checkAssignedRole.Selected = true;
            }
        }
示例#3
0
        private List<SelectRoleEditorViewModel> GetViewModelRoles()
        {
            var roles = new List<SelectRoleEditorViewModel>();
            foreach (var role in RoleManager.Roles)
            {
                // An EditorViewModel will be used by Editor Template:
                var srevm = new SelectRoleEditorViewModel(role);
                roles.Add(srevm);
            }

            return roles;
        }