Exemple #1
0
        public async Task <IActionResult> Index(SearchViewModel model)
        {
            var posts = new List <PostDto>();

            if (model == null)
            {
                return(View(model));
            }

            IEnumerable <PostDto> searchResult;

            if (!string.IsNullOrWhiteSpace(model.Tags))
            {
                searchResult = await _postsService.GetByTags(model.Tags, Request.Cookies["token"]);

                DistinctPosts(posts, searchResult);
            }
            if (!string.IsNullOrWhiteSpace(model.Text))
            {
                searchResult = await _postsService.GetByText(model.Text, Request.Cookies["token"]);

                DistinctPosts(posts, searchResult);
            }
            if (!string.IsNullOrWhiteSpace(model.Username))
            {
                searchResult = await _postsService.GetByUsername(model.Username, Request.Cookies["token"]);

                DistinctPosts(posts, searchResult);
            }

            model.Posts = posts.ToList();

            return(View(model));
        }