Exemplo n.º 1
0
        /// <summary>
        /// Updates <see cref="AuthorList"/> with distinct sorted list of authors in <see cref="AllAssets"/>
        /// </summary>
        private void RefreshAuthorList()
        {
            List <AuthorDropdownViewModel> newAuthorList = new List <AuthorDropdownViewModel>();

            // use GroupBy to get count of assets per author
            foreach (IGrouping <string, AssetViewModel> author in AllAssets.GroupBy(a => a.Author))
            {
                newAuthorList.Add(new AuthorDropdownViewModel(author.Key, author.Count()));
            }

            newAuthorList = newAuthorList.OrderBy(a => a.Author).ToList();

            newAuthorList.Insert(0, new AuthorDropdownViewModel(defaultAuthorValue, 0));

            AuthorList = newAuthorList;

            //clear selection if selected author not in list
            if (AuthorList.Any(a => a.Author == AuthorToFilterBy.Author) == false)
            {
                AuthorToFilterBy = AuthorList[0];
            }
        }