Beispiel #1
0
        public override async Task <IActionResult> IndexAsync([FromQuery] string query, string block)
        {
            var viewModel = new SearchViewModel(GetPageContext(), query);

            if (!string.IsNullOrEmpty(query))
            {
                var hasBlock = !string.IsNullOrEmpty(block);
                var limit    = hasBlock ? 0 : 5;
                if (!hasBlock || block == "games")
                {
                    var searchBlock =
                        await BuildBlockAsync <Game>(query, limit, "Игры", "games");

                    if (searchBlock != null)
                    {
                        viewModel.AddBlock(searchBlock);
                    }
                }

                if (!hasBlock || block == "developers")
                {
                    var searchBlock = await BuildBlockAsync <Developer>(query, limit, "Разработчики", "developers");

                    if (searchBlock != null)
                    {
                        viewModel.AddBlock(searchBlock);
                    }
                }

                if (!hasBlock || block == "topics")
                {
                    var searchBlock =
                        await BuildBlockAsync <Topic>(query, limit, "Темы", "topics");

                    if (searchBlock != null)
                    {
                        viewModel.AddBlock(searchBlock);
                    }
                }

                if (!hasBlock || block == "posts")
                {
                    var searchBlock = await BuildBlockAsync <Post <string> >(query, limit, "Публикации", "posts");

                    if (searchBlock != null)
                    {
                        viewModel.AddBlock(searchBlock);
                    }
                }
            }

            return(View("Index", viewModel));
        }
Beispiel #2
0
        public async Task <IActionResult> Index(string query, string block)
        {
            var viewModel = new SearchViewModel(ViewModelConfig, query);

            if (!string.IsNullOrEmpty(query))
            {
                var hasBlock = !string.IsNullOrEmpty(block);
                var limit    = hasBlock ? 0 : 5;
                if (!hasBlock || block == "games")
                {
                    var games = await SearchEntities <Game>(query, limit);

                    var gamesCount = await CountEntities <Game>(query);

                    var searchBlock = CreateSearchBlock("Игры", Url.Search().BlockUrl("games", query), gamesCount,
                                                        games, x => x.Title,
                                                        x => Url.Base().PublicUrl(x),
                                                        x => _contentHelper.ReplacePlaceholdersAsync(x.Desc));
                    viewModel.AddBlock(await searchBlock);
                }

                if (!hasBlock || block == "news")
                {
                    var news = await SearchEntities <News>(query, limit);

                    var newsCount = await CountEntities <News>(query);

                    var searchBlock = CreateSearchBlock("Новости", Url.Search().BlockUrl("news", query), newsCount,
                                                        news, x => x.Title,
                                                        x => Url.News().PublicUrl(x),
                                                        x => _contentHelper.ReplacePlaceholdersAsync(x.ShortText));
                    viewModel.AddBlock(await searchBlock);
                }

                if (!hasBlock || block == "articles")
                {
                    var articles = await SearchEntities <Article>(query, limit);

                    var articlesCount = await CountEntities <Article>(query);

                    var searchBlock = CreateSearchBlock("Статьи", Url.Search().BlockUrl("articles", query),
                                                        articlesCount,
                                                        articles, x => x.Title,
                                                        x => Url.Articles().PublicUrl(x),
                                                        x => _contentHelper.ReplacePlaceholdersAsync(x.Announce));
                    viewModel.AddBlock(await searchBlock);
                }

                if (!hasBlock || block == "articlesCats")
                {
                    var articlesCats = await SearchEntities <ArticleCat>(query, limit);

                    var articlesCatsCount = await CountEntities <ArticleCat>(query);

                    var searchBlock = CreateSearchBlock("Категории статей",
                                                        Url.Search().BlockUrl("articlesCats", query),
                                                        articlesCatsCount,
                                                        articlesCats, x => x.Title,
                                                        x => Url.Articles().CatPublicUrl(x),
                                                        x => _contentHelper.ReplacePlaceholdersAsync(x.Descr));
                    viewModel.AddBlock(await searchBlock);
                }

                if (!hasBlock || block == "files")
                {
                    var files = await SearchEntities <File>(query, limit);

                    var filesCount = await CountEntities <File>(query);

                    var searchBlock = CreateSearchBlock("Файлы", Url.Search().BlockUrl("files", query),
                                                        filesCount,
                                                        files, x => x.Title,
                                                        x => Url.Files().PublicUrl(x),
                                                        x => _contentHelper.ReplacePlaceholdersAsync(x.Announce));
                    viewModel.AddBlock(await searchBlock);
                }

                if (!hasBlock || block == "filesCat")
                {
                    var fileCats = await SearchEntities <FileCat>(query, limit);

                    var fileCatsCount = await CountEntities <FileCat>(query);

                    var searchBlock = CreateSearchBlock("Категории файлов",
                                                        Url.Search().BlockUrl("filesCat", query),
                                                        fileCatsCount,
                                                        fileCats, x => x.Title,
                                                        x => Url.Files().CatPublicUrl(x),
                                                        x => _contentHelper.ReplacePlaceholdersAsync(x.Descr));
                    viewModel.AddBlock(await searchBlock);
                }

                if (!hasBlock || block == "galleryCats")
                {
                    var galleryCats = await SearchEntities <GalleryCat>(query, limit);

                    var galleryCatsCount = await CountEntities <GalleryCat>(query);

                    var searchBlock = CreateSearchBlock("Категории картинок",
                                                        Url.Search().BlockUrl("galleryCats", query),
                                                        galleryCatsCount,
                                                        galleryCats, x => x.Title,
                                                        x => Url.Gallery().CatPublicUrl(x),
                                                        x => _contentHelper.ReplacePlaceholdersAsync(x.Desc));
                    viewModel.AddBlock(await searchBlock);
                }
            }
            return(View(viewModel));
        }