public static ObservableCollection <PeopleGroup> CreateGroups(IEnumerable <Person> people, bool groupByLastName) { var pgs = new Dictionary <string, PeopleGroup> (); var sorted = groupByLastName ? people.OrderBy(x => x.Anzeigename) : people.OrderBy(x => x.Index); foreach (var p in sorted) { try { var g = groupByLastName && p.IsPerson ? p.Name?.Substring(0, 1).ToUpper() : p.SafeDepartment; if (!pgs.TryGetValue(g, out PeopleGroup pg)) { pg = new PeopleGroup(g); pgs.Add(g, pg); } pg.People.Add(p); } catch (NullReferenceException) { //remove that person from favs } } return(new ObservableCollection <PeopleGroup> (pgs.Values.OrderBy(x => x.Title))); }
void CreateGroups() { Groups = PeopleGroup.CreateGroups( favoritesRepository.GetAll(), groupByLastName); OnPropertyChanged("Groups"); }
void CreateGroups() { People = new ObservableCollection <Person> (favoritesRepository.GetAll()); Groups = PeopleGroup.CreateGroups( favoritesRepository.GetAll(), groupByLastName); OnPropertyChanged("Groups"); }
public static ObservableCollection <PeopleGroup> CreateGroups(IEnumerable <Person> people, bool groupByLastName) { var pgs = new Dictionary <string, PeopleGroup> (); foreach (var p in people.OrderBy(x => x.LastName)) { var g = groupByLastName ? p.SafeLastName.Substring(0, 1).ToUpperInvariant() : p.SafeDisplayName.Substring(0, 1).ToUpperInvariant(); PeopleGroup pg; if (!pgs.TryGetValue(g, out pg)) { pg = new PeopleGroup(g); pgs.Add(g, pg); } pg.People.Add(p); } return(new ObservableCollection <PeopleGroup> (pgs.Values.OrderBy(x => x.Title))); }
/// <summary> /// Groups people by the initial letter of their last name /// </summary> private void SetGroupedPeople() { Groups = PeopleGroup.CreateGroups(search.Results, groupByLastName); OnPropertyChanged("Groups"); }
/// <summary> /// Groups people by the initial letter of their last name /// </summary> private void SetGroupedPeople() { Groups = PeopleGroup.CreateGroups(search.Results, search.Property != SearchProperty.Wichtig); OnPropertyChanged("Groups"); }