/// <summary> /// Saves the search results history. /// </summary> /// <param name="restaurant">The restaurant.</param> /// <returns></returns> /// <exception cref="ValidationException">The restaurant entity is not valid! - null</exception> public SearchResultsHistory SaveSearchResultsHistory(SearchResultsHistory searchResultsHistory) { searchResultsHistory.CreatedDate = DateTime.Now; UnitOfWork.Repository <SearchResultsHistory>().Create(searchResultsHistory); UnitOfWork.SaveChanges(); return(searchResultsHistory); }
public async Task <SearchResultsHistory> InsertSearchResultsHistory(List <SearchResult> searchResults, int searchTermHistoryId) { SearchResultsHistory searchResultsHistory = new SearchResultsHistory(); try { searchResultsHistory.SearchTermHistoryId = searchTermHistoryId; searchResultsHistory.Result = JsonConvert.SerializeObject(searchResults); _context.SearchResultsHistory.Add(searchResultsHistory); await _context.SaveChangesAsync(); } catch (Exception ex) { throw ex; } return(searchResultsHistory); }
public async Task <Word> Search(string searchTerm) { Word word = new Word(); try { word.SearchTerm = searchTerm; List <SearchTermHistory> termHistory = await _repository.GetSearchTermHistory(searchTerm); if (termHistory == null || termHistory.Count <= 0) { SearchTermHistory insertSearchTermHistory = await _repository.InsertSearchTermHistory(searchTerm); word.SearchResults = await _repository.SearchResultsFromDictionaryApi(searchTerm); if (word.SearchResults != null && word.SearchResults.Count > 0) { word.IsOffensive = word.SearchResults.FirstOrDefault().Meta.Offensive; SearchResultsHistory insertSearchResultHistory = await _repository.InsertSearchResultsHistory(word.SearchResults, insertSearchTermHistory.Id); } } else { int searchTermHistoryId = termHistory.FirstOrDefault().Id; List <SearchResultsHistory> resultHistory = await _repository.GetSearchResultHistory(searchTermHistoryId); if (resultHistory.Count > 0) { var result = resultHistory.FirstOrDefault(); word.SearchResults = JsonConvert.DeserializeObject <List <SearchResult> >(result.Result); word.IsOffensive = word.SearchResults.FirstOrDefault().Meta.Offensive; } } } catch (Exception ex) { throw ex; } return(word); }