示例#1
0
        public ActionResult Index(CompositionFilter filter)
        {
            var filteredCompositions = _filterService.ApplyFilter(filter);

            InitializeFilterModel(filter);
            ViewBag.Filter = filter;

            return(View(filteredCompositions));
        }
示例#2
0
        private void InitializeFilterModel(CompositionFilter filter)
        {
            if (filter == null)
            {
                filter = new CompositionFilter();
            }

            var genres    = _genreService.GetAllGenres();
            var authors   = _authorService.GetAllAuthors();
            var types     = _typeService.GetAllTypes();
            var languages = _languageService.GetAllLanguages();

            foreach (var genre in genres)
            {
                filter.Genres.Add(
                    new CheckBoxViewModel
                {
                    Id        = genre.Id.Value,
                    Value     = genre.Name,
                    IsChecked = filter.SelectedGenres.Contains(genre.Id.Value)
                });
            }
            foreach (var author in authors)
            {
                filter.Authors.Add(
                    new CheckBoxViewModel
                {
                    Id        = author.Id.Value,
                    Value     = author.FirstName + " " + author.LastName + " " + author.DateBirth.ToShortDateString(),
                    IsChecked = filter.SelectedAuthors.Contains(author.Id.Value)
                });
            }
            foreach (var type in types)
            {
                filter.Types.Add(
                    new CheckBoxViewModel
                {
                    Id        = type.Id.Value,
                    Value     = type.Name,
                    IsChecked = filter.SelectedTypes.Contains(type.Id.Value)
                });
            }
            foreach (var lang in languages)
            {
                filter.Langs.Add(
                    new CheckBoxViewModel
                {
                    Id        = lang.Id.Value,
                    Value     = lang.ShortCode,
                    IsChecked = filter.SelectedLangs.Contains(lang.Id.Value)
                });
            }
        }