public ActionResult Search(SearchRecipe criteria) { criteria = criteria ?? new SearchRecipe(); var recipes = db.Recipes.Include(r => r.Season).Include(r => r.Type); if (!string.IsNullOrWhiteSpace(criteria.Name)) { recipes = recipes.Where(x => x.Name.ToLower().Contains(criteria.Name.ToLower())); } if (criteria.SeasonID != null) { recipes = recipes.Where(x => x.SeasonID == criteria.SeasonID); } if (criteria.TypeID != null) { recipes = recipes.Where(x => x.TypeID == criteria.TypeID); } if (criteria.IsFish == true) { recipes = recipes.Where(x => x.IsFish); } if (criteria.IsGlutenFree == true) { recipes = recipes.Where(x => x.IsGlutenFree); } if (criteria.IsGlutenFreeAdaptable == true) { recipes = recipes.Where(x => x.IsGlutenFreeAdaptable); } if (criteria.IsMeat == true) { recipes = recipes.Where(x => x.IsMeat); } if (criteria.IsVegan == true) { recipes = recipes.Where(x => x.IsVegan); } if (criteria.IsVeganAdaptable == true) { recipes = recipes.Where(x => x.IsVeganAdaptable); } if (criteria.IsVegetarian == true) { recipes = recipes.Where(x => x.IsVegetarian); } ViewBag.SearchResult = recipes.ToList(); ViewBag.SeasonID = new SelectList(db.Seasons, "ID", "Name"); ViewBag.TypeID = new SelectList(db.Types, "ID", "Name"); return(View(criteria)); }
public List <Recipe> GetSearchRecipe(string title) { SearchRecipe r = new SearchRecipe(); HttpClientHandler handler = new HttpClientHandler(); handler.UseDefaultCredentials = true; using (var client = new HttpClient(handler)) { client.BaseAddress = new Uri(baseUrl); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*")); client.DefaultRequestHeaders.Connection.Add("keep-alive"); string vegan; if (Vegan) { vegan = "vegan"; } else { vegan = ""; } try { var response = client.GetAsync($"recipes/complexSearch?diet={vegan}&query={title}&number=5&apiKey={authKey}").Result; if (response.IsSuccessStatusCode) { r = response.Content.ReadAsAsync <SearchRecipe>().Result; } else { return(null); } } catch (Exception e) { Console.WriteLine(e); throw; } } return(r.results); }
public async void searchButton_Click(object sender, EventArgs e) { SearchRecipe recipe = new SearchRecipe(); var recipes = await recipe.CallApiAsync(textBox1.Text); List <Recipe> output = JsonConvert.DeserializeObject <List <Recipe> >(recipes); foreach (var test in output) { test.setImageFromUrl(); } dataGridView1.DataSource = output; dataGridView1.Columns["image"].Visible = false; dataGridView1.Columns["id"].Visible = false; dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; }
public SearchRecipeViewModel(ISettings settings, ILogger logger) { this._searchRecipe = new SearchRecipe(settings, logger).AddTo(this.CompositeDisposable); // Property // 現在ページ this.CurrentPage = this._searchRecipe.CurrentPage.ToReadOnlyReactiveProperty().AddTo(this.CompositeDisposable); // 最大ページ数 this.MaxPage = this._searchRecipe.MaxPage.ToReadOnlyReactiveProperty().AddTo(this.CompositeDisposable); // 複数ページフラグ this.IsMultiPage = this.MaxPage.Select(x => x >= 2).ToReadOnlyReactiveProperty().AddTo(this.CompositeDisposable); // ページリスト this.PageList = this.MaxPage .CombineLatest(this.CurrentPage, (max, current) => (max, current)) .Select(x => Enumerable .Range(x.current - 4, 10) .Where(i => i >= 1 && i <= x.max) .ToArray() ) .ToReadOnlyReactivePropertySlim() .AddTo(this.CompositeDisposable); // 検索ワード this.SearchWord = this._searchRecipe.SearchWord.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable); // 検索対象フラグ:タイトル this.IsTitleSearchTarget = this._searchRecipe.IsTitleSearchTarget.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable); // 検索対象フラグ:材料 this.IsIngredientSearchTarget = this._searchRecipe.IsIngredientSearchTarget.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable); // 検索対象フラグ:手順 this.IsStepSearchTarget = this._searchRecipe.IsStepSearchTarget.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable); // 最終利用日 this.LastUsedDate = this._searchRecipe.LastUsedDate.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable); // 最終利用日以前フラグ this.IsBeforeLastUsedDate = this._searchRecipe.IsBeforeLastUsedDate.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable); // 利用回数 this.UsageCount = this._searchRecipe.UsageCount.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable); // 利用回数以上フラグ this.IsUsageCountMoreThan = this._searchRecipe.IsUsageCountMoreThan.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable); // アーカイブを含むかどうかのフラグ this.IncludingArchive = this._searchRecipe.IncludingArchive.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable); // 検索結果 this.SearchResult = this._searchRecipe .Result .Select(x => x.Select(r => Creator.CreateRecipeViewModelInstance(settings, logger, r) ).ToArray() ).ToReadOnlyReactiveProperty() .AddTo(this.CompositeDisposable); // タグ候補 this.TagList = this._searchRecipe.TagList.ToReadOnlyReactiveCollection().AddTo(this.CompositeDisposable); // 評価 this.Ratings = this._searchRecipe.Ratings.ToReadOnlyReactiveCollection().AddTo(this.CompositeDisposable); // 追加したソート条件 this.SortConditions = this._searchRecipe.SortConditions.ToReadOnlyReactiveCollection().AddTo(this.CompositeDisposable); // 検索条件リスト this.SortItems = this._searchRecipe.SortItems.ToReadOnlyReactiveCollection().AddTo(this.CompositeDisposable); // 検索条件プラグインリスト this.SearchConditionPlugins = this._searchRecipe.SearchConditionPlugins.ToReadOnlyReactiveCollection().AddTo(this.CompositeDisposable); // 追加されたプラグイン検索条件 this.PluginSearchConditions = this._searchRecipe.PluginSearchConditions.ToReadOnlyReactiveCollection(x => { var(view, viewModel) = Creator.CreateRecipeSearchConditionViewAndViewModel(x); return(new ViewViewModelPair <UserControl, IRecipeSearchConditionViewModel>(view, viewModel)); }).AddTo(this.CompositeDisposable); // ロード中フラグ this.IsBusy = this._searchRecipe.IsBusy.ToReadOnlyReactiveProperty().AddTo(this.CompositeDisposable); // Command // 検索 this.SearchCommand.Subscribe(_ => this._searchRecipe.Search()).AddTo(this.CompositeDisposable); // ソート条件追加 this.AddSortConditionCommand.Subscribe(() => this._searchRecipe.AddSortCondition()).AddTo(this.CompositeDisposable); // ソート条件削除 this.RemoveSortConditionCommand.Subscribe(s => this._searchRecipe.RemoveSortCondition(s)).AddTo(this.CompositeDisposable); // プラグイン検索条件追加 this.AddPluginSearchConditionCommand.Where(p => p != null).Subscribe(p => this._searchRecipe .AddPluginSearchCondition(p) ).AddTo(this.CompositeDisposable); // プラグイン検索条件削除 this.RemovePluginSearchConditionCommand.Subscribe(c => this._searchRecipe.RemovePluginSearchCondition(c.RecipeSearchCondition)).AddTo(this.CompositeDisposable); // 前ページへ戻る this.PreviousCommand = this.CurrentPage.Select(c => c > 1).ToReactiveCommand().AddTo(this.CompositeDisposable); this.PreviousCommand.Subscribe(() => { this._searchRecipe.GoToPreviousPage(); }).AddTo(this.CompositeDisposable); // 次ページへ進む this.NextCommand = this.CurrentPage.CombineLatest(this.MaxPage, (c, m) => c < m).ToReactiveCommand().AddTo(this.CompositeDisposable); this.NextCommand.Subscribe(() => { this._searchRecipe.GoToNextPage(); }).AddTo(this.CompositeDisposable); // ページ遷移 this.TransitionCommand.Subscribe(page => { this._searchRecipe.PageTransition(page); }).AddTo(this.CompositeDisposable); // レシピエディタ起動 this.EditRecipeCommand.Subscribe(rvm => { var vm = new RecipeDetailViewModel(settings, logger); vm.RecipeViewModel.Value = rvm; vm.RecipeView.Value = Creator.CreateRecipeEditorViewInstance(settings, logger, rvm); this.Messenger.Raise(new TransitionMessage(vm, "OpenEditRecipeWindow")); }).AddTo(this.CompositeDisposable); // レシピ削除 this.DeleteRecipeCommand.Subscribe(rvm => { var vm = new DialogWindowViewModel("削除確認", "レシピを削除します。よろしいですか。", DialogWindowViewModel.DialogResult.Yes, DialogWindowViewModel.DialogResult.No ); using (vm) { this.Messenger.Raise(new TransitionMessage(vm, TransitionMode.Modal, "OpenDialogWindow")); if (vm.Result != DialogWindowViewModel.DialogResult.Yes) { return; } rvm.DeleteRecipeCommand.Execute(this.Messenger); // 結果を再読込 this.SearchCommand.Execute(); } }).AddTo(this.CompositeDisposable); }