public RoleDetailViewModel(ApplicationRole role) { Id = role.Id; RoleName = role.Name; var items = new List <SelectListItem>(); foreach (PermissionNames p in Enum.GetValues(typeof(PermissionNames))) { items.Add(new SelectListItem { Text = p.ToString().ToTitleFriendlyString(), Value = p.ToString(), Selected = role.HasPermission(p) }); } items.Sort((a, b) => a.Text.CompareTo(b.Text)); InitialPermissionList = items; SelectedPermissions = items.Where(z => z.Selected).ConvertAll(z => z.Value).ToList(); }