Ejemplo n.º 1
0
        public Task <YoutubeSearchResult> Search(YoutubeSearchCriteria criteria)
        {
            var query = _repository.YoutubeVideos;

            if (!criteria.SearchPhrase.IsNullOrEmpty())
            {
                query = query.Where(x => x.VideoTitle.Contains(criteria.SearchPhrase));
            }

            var videoIds = query.Skip(criteria.Skip)
                           .Take(criteria.Take)
                           .Select(x => x.Id)
                           .ToList();



            var result = new YoutubeSearchResult
            {
                TotalCount = _repository.YoutubeVideos.Count(),
                Results    = _repository.YoutubeVideos.Where(x => videoIds.Contains(x.Id)).ToArray().OrderBy(x => videoIds.IndexOf(x.Id)).ToList()
            };

            return(Task.FromResult(result));
        }
Ejemplo n.º 2
0
 public ActionResult <string> Search([FromBody] YoutubeSearchCriteria criteria)
 {
     return(Ok(new { result = _searchService.Search(criteria) }));
 }