Exemple #1
0
        private void UpdateCategoriesForShow(FavShowData show, List <String> categories)
        {
            categories.Add("all");

            //Check existing cats
            foreach (var cat in _categories)
            {
                if (!cat.Setting.Enabled)
                {
                    continue;
                }

                var vm = cat.Shows.FirstOrDefault(v => v.Show == show);
                if (!categories.Contains(cat.Title) && vm != null) //should not be there, but is there
                {
                    cat.RemoveShow(vm);
                }
                else if (categories.Contains(cat.Title) && vm == null)   //should be there, but isn't
                {
                    cat.AddShow(new ShowTileViewModel(show));
                }
                else
                {
                    cat.Sort();
                }
            }

            //Remove empty cats or disabled cats
            _categories.Where(c => !c.Shows.Any() || !c.Setting.Enabled).ToList().ForEach(c => _categories.Remove(c));


            //Add non existing cats
            foreach (var cat in categories)
            {
                if (_categories.Any(c => c.Title == cat))
                {
                    continue;
                }
                var settings = Settings.Instance.CategorySettings.First(s => s.Title == cat);
                if (!settings.Enabled)
                {
                    continue;
                }
                var newCat = new ShowCategory();
                newCat.Title   = cat;
                newCat.Setting = settings;
                newCat.AddShow(new ShowTileViewModel(show));

                _categories.Add(newCat);
            }

            _categories.Sort(CategoryComparer);
        }
        private void UpdateCategoriesForShow(FavShowData show, List <String> categories)
        {
            categories.Add("all");

            //Check existing cats
            foreach (var cat in _categories)
            {
                var vm = cat.Shows.FirstOrDefault(v => v.Show == show);
                if (!categories.Contains(cat.Title) && vm != null) //should not be there, but is there
                {
                    cat.Shows.Remove(vm);
                }
                else if (categories.Contains(cat.Title) && vm == null)   //should be there, but isn't
                {
                    cat.Shows.Add(new ShowTileViewModel(show));
                    cat.Shows.Sort(CategoryInnerOrders[cat.Title]);
                }
            }

            //Remove empty cats
            _categories.Where(c => !c.Shows.Any()).ToList().ForEach(c => _categories.Remove(c));


            //Add non existing cats
            foreach (var cat in categories)
            {
                if (_categories.Any(c => c.Title == cat))
                {
                    continue;
                }
                var newCat = new ShowCategory();
                newCat.Title       = cat;
                newCat.Description = CategoryDescriptions[cat];
                newCat.Shows.Add(new ShowTileViewModel(show));

                _categories.Add(newCat);
            }

            _categories.Sort(CategoryComparer);
        }