private void InitCollection() { try { if (this.CategoryViewModels == null) { this.CategoryViewModels = new ObservableCollection<CategoryViewModel>(); } this.BuildCategoryList(); this.SelectedCategory = this.CategoryViewModels.First(); } catch (Exception e) { this.Logger().ErrorFormat(e.Message); } }
private void BuildCategoryList(IEnumerable<Video> videos = null) { var selectedCategoryName = this.SelectedCategory == null ? String.Empty : this.SelectedCategory.Name; this.CategoryViewModels.Clear(); var categoryViewModels = this._categoryService.GetCategories() .Select(g => new CategoryViewModel { Count = g.Value, Name = g.Key }); this.CategoryViewModels.AddRange(categoryViewModels); this.SelectedCategory = this.CategoryViewModels.SingleOrDefault(c => c.Name == selectedCategoryName) ?? this.CategoryViewModels.First(); }