///////////////////
        //
        // Helpers
        //
        //////////////////////

        private SearchHistoryListDto CreateSearchHistoryResultDto(Searches searches)
        {
            var dto = new SearchHistoryListDto();

            var s = "";

            if (searches.SearchString != null)
            {
                s = _dataService.BuildSearchString(searches.SearchString, true);
            }
            var stype = _dataService.SearchTypeLookup(searches.SearchType);

            dto.SearchLink = Url.Link(
                nameof(SearchController.Search),
                new
            {
                s,
                stype
            });

            dto.SearchMethod = searches.SearchType;
            dto.SearchString = searches.SearchString;
            dto.Date         = searches.Date;

            return(dto);
        }
Exemple #2
0
        //examples
        // http://localhost:5001/api/search?s=code&stype=0&page=10&pageSize=5
        // http://localhost:5001/api/search?s=code,app,program
        public ActionResult Search([FromQuery] SearchQuery searchparams, [FromQuery] PagingAttributes pagingAttributes)
        {
            (int userId, bool useridok) = GetAuthUserId();

            Console.WriteLine("Got user: "******"Got searchparams: " + searchparams.s);

                //checking of params
                if (searchparams.stype >= 0 && searchparams.stype <= 3)
                {
                    //do search, fix page also if needed as a bonus
                    var search = _dataService.Search(userId, searchparams.s, searchparams.stype, pagingAttributes);

                    // try to fix searchsting for link generation if it seems useable but ugly
                    searchparams.s = _dataService.BuildSearchString(searchparams.s, true);

                    var result = CreateResult(search, searchparams, pagingAttributes);
                    if (result != null)
                    {
                        return(Ok(result));
                    }
                    else
                    {
                        return(NoContent());
                    }
                }
                else if (searchparams.stype >= 4 && searchparams.stype <= 5)
                {
                    //wrong search type, redirect
                    return(RedirectToAction("WordRank", new { searchparams.s, searchparams.stype }));
                }
            }
            return(BadRequest());
        }