public async Task <IViewComponentResult> InvokeAsync()
        {
            try
            {
                //if (_cache == null)
                //{
                var controller = new ContentController();
                _cache = ContentApi.Search(25, 1, null, null, null, null);
                //}

                foreach (var content in _cache)
                {
                    if (content.Type == "answer")
                    {
                        content.Title    = parent.Title;
                        content.ParentId = parent.Id;
                    }
                }
                return(View(_cache));
            }
            catch (Exception e)
            {
                return(View(new List <Content>()));
            }
        }
Ejemplo n.º 2
0
        public List <ContentViewModel> Search(SearchRequest request)
        {
            request.PageSize = request.PageSize ?? 10;
            request.Page     = request.Page ?? 1;

            var contents     = ContentApi.Search(request.PageSize.Value, request.Page, request.Type, request.Text, request.OrderBy, request.TagId);
            var searchResult = contents.Select(c => c.AsViewModel()
                                               .WithTags()
                                               .WithChildrenCount()
                                               .WithUser()
                                               .WithEditedBy()).ToList();

            return(searchResult);
        }
Ejemplo n.º 3
0
        public IActionResult Search(int p, string o, string q, int t)
        {
            var db = new DbApi();

            if (p == 0)
            {
                p = 1;
            }

            int?tagId = t;

            if (t == 0)
            {
                tagId = null;
            }

            if (o == null)
            {
                o = "created-desc";
            }

            var content = ContentApi.Search(10, p, "question", q, o, tagId);

            var result = new ContentListModel();

            result.Content      = content;
            result.ResultsCount = ContentApi.GetSearchResultCount("question", q, t);

            result.MaxPages = Math.Min(5, (int)Math.Floor((double)result.ResultsCount / 10));

            if (result.ResultsCount % 10 != 0)
            {
                result.MaxPages++;
            }

            result.Page       = p;
            result.SearchText = q;
            result.OrderBy    = o;
            result.Tags       = TagApi.Select().OrderByDescending(tag => tag.Count).Take(8).ToList();

            return(View("Results", result));
        }