private async void OpenFile() { SearchResultItemViewModel <T> selectedItem = SelectedItem; if (selectedItem == null) { return; } LibgenObject selectedLibgenObject = selectedItem.LibgenObject; if (selectedLibgenObject == null || !selectedLibgenObject.FileId.HasValue) { return; } LibraryFile file = await MainModel.LoadFileAsync(selectedLibgenObject.FileId.Value); string filePath = file.FilePath; if (File.Exists(filePath)) { Process.Start(filePath); } else { ShowMessage(Localization.ErrorMessageTitle, Localization.GetFileNotFoundErrorText(filePath)); } }
public void SetUp() { _eventAggregator = Substitute.For <IEventAggregator>(); _application = Substitute.For <IApplication>(); _carProfileDataEvent = Substitute.For <CarProfileDataEvent>(); _eventAggregator.GetEvent <CarProfileDataEvent>().Returns(_carProfileDataEvent); _uut = new SearchResultItemViewModel(_eventAggregator, _application); }
private void OpenDetails() { SearchResultItemViewModel <T> selectedItem = SelectedItem; if (selectedItem == null) { return; } OpenDetails(selectedItem.LibgenObject); }
/// <summary> /// Search news on New York Times service /// </summary> /// <param name="keywords">keywords to search</param> /// <param name="page">Used for pagination</param> /// <returns></returns> public async Task <SearchResultsViewModel> SearchNews(string keywords, string page) { SearchResultsViewModel result = new SearchResultsViewModel(); try { var builder = new UriBuilder(URL); var query = HttpUtility.ParseQueryString(builder.Query); query["api-key"] = APIKEY; query["page"] = page; query["q"] = keywords; builder.Query = query.ToString(); string url = builder.ToString(); string responseBody = await client.GetStringAsync(url).ConfigureAwait(false); dynamic jsonResponse = JsonConvert.DeserializeObject(responseBody); SearchResultItemViewModel item; int itemsFound = jsonResponse.response.meta.hits > 10 ? 10 : jsonResponse.response.meta.hits; for (int i = 1; i < itemsFound; i++) { item = new SearchResultItemViewModel(); item.ArticleName = jsonResponse.response.docs[i].headline.main; item.ArticleLink = jsonResponse.response.docs[i].web_url; item.ArticleSource = jsonResponse.response.docs[i].source; result.SearchResultsList.Add(item); } return(result); } catch (ArgumentOutOfRangeException e) { Console.WriteLine("\nException Caught!"); Console.WriteLine("Message :{0} ", e.Message); return(result); } catch (HttpRequestException e) { Console.WriteLine("\nException Caught!"); Console.WriteLine("Message :{0} ", e.Message); return(null); } }
private SearchResultViewModel createViewModel(SearchResponse response) { var model = new SearchResultViewModel(); model.QueryWord = response.QueryWord; foreach (var item in response.Results) { var itemViewModel = new SearchResultItemViewModel(); itemViewModel.Id = item.Id; itemViewModel.Text = item.Title; itemViewModel.SearchEngine = item.SearchEngine.ToString(); model.Items.Add(itemViewModel); } return(model); }
public List <SearchResultItemViewModel> Search(string searchQuery) { List <SearchResultItemViewModel> result = new List <SearchResultItemViewModel>(); foreach (NonFictionBook book in localDatabase.SearchNonFictionBooks(searchQuery, DEFAULT_MAXIMUM_SEARCH_RESULT_COUNT)) { SearchResultItemViewModel resultItem = new SearchResultItemViewModel { Id = book.Id, Title = book.Title, Authors = book.Authors, Series = book.Series, Year = book.Year, Publisher = book.Publisher, Format = book.Format, FileSize = FileSizeToString(book.SizeInBytes, false), Ocr = book.Searchable == "1" }; result.Add(resultItem); } return(result); }
/// <summary> /// Gets the search result item view model for the original item. /// </summary> /// <param name="item">The item to be represented by the view model.</param> /// <param name="content">The content to be displayed for this item.</param> /// <returns>A new <see cref="SearchResultItemViewModel"/> instance that represents the item.</returns> private SearchResultItemViewModel GetSearchResultItemViewModel(object item, string content) { var viewModel = new SearchResultItemViewModel { Content = content }; if (item is IEntity entity) { var type = entity.GetType(); if (type.IsDynamicProxyType()) { type = type.BaseType; } viewModel.Guid = entity.Guid; viewModel.DetailKey = $"{type.Name}Guid"; } return(viewModel); }
private IEnumerable <SearchResultItemViewModel> GetSearchResults(SearchResultsViewModel paramForm, int page) { const int PAGE_SIZE = ConstHelper.CONST_PAGE_SIZE; string emailAddress = HttpContext.Current.User.Identity.Name.ToString(); if (!global.IsUniqueEmailAddress(emailAddress)) { Account userAccount = global.GetAccount(emailAddress); int searchCategory = paramForm.SearchCategory; int searchSubCategory = paramForm.SearchSubcategory; int tradeCategory = paramForm.TradeCategory; int tradeSubCategory = paramForm.TradeSubcategory; var itemResults = (searchCategory > 0) ? db.Item .Join(db.ItemDetail, it => it.ItemId, itd => itd.ItemId, (it, itd) => new { it, itd }) .Join(db.Account, ai => ai.it.AccountId, ac => ac.AccountId, (ai, ac) => new { ai, ac }) .OrderByDescending(od => od.ai.it.CategoryId == ((searchCategory > 0) ? searchCategory : -1)) .ThenBy(od => od.ai.it.SubcategoryId == ((searchSubCategory > 0) ? searchSubCategory : -1)) .ThenBy(od => od.ai.it.TradeCategoryId == ((tradeCategory > 0) ? tradeCategory : -1)) .ThenBy(od => od.ai.it.TradeSubcategoryId == ((tradeSubCategory > 0) ? tradeSubCategory : -1)) .ThenBy(od => od.ai.itd.UploadDate) .ThenBy(od => od.ac.Country == userAccount.Country) .ThenBy(od => od.ac.State == paramForm.State) .ThenBy(od => od.ac.State == userAccount.State) .ThenBy(od => od.ac.City == paramForm.City) .ThenBy(od => od.ac.City == userAccount.City) .Where(i => (i.ai.it.Name.ToLower().Contains(paramForm.SearchQuery.ToLower()) || i.ai.it.Caption.ToLower().Contains(paramForm.SearchQuery.ToLower()) || i.ai.it.Description.ToLower().Contains(paramForm.SearchQuery.ToLower())) && i.ai.itd.ItemStatus == (int)ItemStatusType.Normal). Skip(page * PAGE_SIZE).Take(PAGE_SIZE).ToList() : db.Item .Join(db.ItemDetail, it => it.ItemId, itd => itd.ItemId, (it, itd) => new { it, itd }) .Join(db.Account, ai => ai.it.AccountId, ac => ac.AccountId, (ai, ac) => new { ai, ac }) .OrderByDescending(od => od.ai.it.TradeCategoryId == ((tradeCategory > 0) ? tradeCategory : -1)) .ThenBy(od => od.ai.it.TradeSubcategoryId == ((tradeSubCategory > 0) ? tradeSubCategory : -1)) .ThenBy(od => od.ai.it.CategoryId == ((searchCategory > 0) ? searchCategory : -1)) .ThenBy(od => od.ai.it.SubcategoryId == ((searchSubCategory > 0) ? searchSubCategory : -1)) .ThenBy(od => od.ai.itd.UploadDate) .ThenBy(od => od.ac.Country == userAccount.Country) .ThenBy(od => od.ac.State == paramForm.State) .ThenBy(od => od.ac.State == userAccount.State) .ThenBy(od => od.ac.City == paramForm.City) .ThenBy(od => od.ac.City == userAccount.City) .Where(i => (i.ai.it.Name.ToLower().Contains(paramForm.SearchQuery.ToLower()) || i.ai.it.Caption.ToLower().Contains(paramForm.SearchQuery.ToLower()) || i.ai.it.Description.ToLower().Contains(paramForm.SearchQuery.ToLower())) && i.ai.itd.ItemStatus == (int)ItemStatusType.Normal). Skip(page * PAGE_SIZE).Take(PAGE_SIZE).ToList(); if (itemResults.Count > 0) { List <SearchResultItemViewModel> resultsList = new List <SearchResultItemViewModel>(); for (int x = 0; x < itemResults.Count; x++) { SearchResultItemViewModel newItem = new SearchResultItemViewModel(); newItem.ItemId = itemResults[x].ai.it.ItemId; newItem.Name = itemResults[x].ai.it.Name; newItem.Caption = itemResults[x].ai.it.Caption; newItem.Description = itemResults[x].ai.it.Description; newItem.IsYours = (userAccount.AccountId == itemResults[x].ai.it.AccountId) ? true : false; Image itemImage = imaging.ServeImage(itemResults[x].ai.it.ItemId); if (itemImage != null) { newItem.ImageSource = itemImage.ImageSource; } resultsList.Add(newItem); } return(resultsList); } } return(null); }