public MovieSearchResponseModel(MovieSearchListViewModel model) { if (model == null) { return; } SearchDepth = model.SearchDepth; Title = model.Title; Movies = model.Movies.Select(r => new MovieListResponseModel(r)).ToList(); }
public async Task <MovieSearchListViewModel> Search(string keyword) { var result = new MovieSearchListViewModel { Title = "Found Results by Title", SearchDepth = 0 }; result.Movies = await _db.Movies .FilterByTitleStartsWith(keyword) .OrderBy(r => r.Title) .GoToCursor(_userStaticContext.Cursor) .Select(MovieListViewModel.Projection) .ToListAsync(); //If we can't find anything starts with keyword maybe it's a word in The Title if (!result.Movies.Any()) { result.SearchDepth++; result.Movies = await _db.Movies .FilterByTitleInclude(keyword) .OrderBy(r => r.Title) .GoToCursor(_userStaticContext.Cursor) .Select(MovieListViewModel.Projection) .ToListAsync(); } //If we can't find anything maybe it's name of the actor if (!result.Movies.Any()) { result.SearchDepth++; result.Title = "Found results by Actors"; result.Movies = await _db.Movies .FilterByActorNameInclude(keyword) .OrderBy(r => r.Title) .GoToCursor(_userStaticContext.Cursor) .Select(MovieListViewModel.Projection) .ToListAsync(); } //If we can't find anything lastly we can try to find something in the genre. if (!result.Movies.Any()) { result.SearchDepth++; result.Title = "Found results by Genre"; result.Movies = await _db.Movies .FilterByGenreInclude(keyword) .OrderBy(r => r.Title) .GoToCursor(_userStaticContext.Cursor) .Select(MovieListViewModel.Projection) .ToListAsync(); } if (!result.Movies.Any()) { result.SearchDepth++; result.Title = "Sorry, nothing found ¯\\_(ツ)_/¯"; } return(result); }