private void GetData() { HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://api.yummly.com/v1/api/"); // Add an Accept header for JSON format. client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.GetAsync("recipes?_app_id=0fd5d39d&_app_key=c80aa038f437173fdf436a5f4ca5cbeb&q=onion+soup").Result; if (response.IsSuccessStatusCode) { string users = response.Content.ReadAsStringAsync().Result; SearchRecipes objSearchRecipes = new SearchRecipes(); objSearchRecipes = JsonConvert.DeserializeObject <SearchRecipes>(users.ToString()); // var users = response.Content.ReadAsStringAsync(); // usergrid.ItemsSource = users; } else { // MessageBox.Show("Error Code" + // response.StatusCode + " : Message - " + response.ReasonPhrase); } }
// GET: SearchRecipes/Details/5 public async Task <IActionResult> Details(int?id) { var client = new RestClient("https://spoonacular-recipe-food-nutrition-v1.p.rapidapi.com/recipes/findByIngredients?number=5&ranking=1&ignorePantry=false&ingredients=apples%2Cflour%2Csugar"); var request = new RestRequest(Method.GET); request.AddHeader("x-rapidapi-host", "spoonacular-recipe-food-nutrition-v1.p.rapidapi.com"); request.AddHeader("x-rapidapi-key", "f2216af4f5msh71430f2e651f9dap1350a2jsn801bc5c5aa5f"); IRestResponse response = client.Execute(request); var data = response.Content; SearchRecipes jsonResults = JsonConvert.DeserializeObject <SearchRecipes>(data); return(View(await _context.SearchRecipes.ToListAsync())); if (id == null) { return(NotFound()); } var searchRecipes = await _context.SearchRecipes .FirstOrDefaultAsync(m => m.id == id); if (searchRecipes == null) { return(NotFound()); } return(View(searchRecipes)); }
public async Task <IActionResult> Edit(int id, [Bind("id,MyProperty,results,baseUri,offset,number,totalRequests,processingTimeMs,expires,isStale")] SearchRecipes searchRecipes) { if (id != searchRecipes.id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(searchRecipes); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SearchRecipesExists(searchRecipes.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(searchRecipes)); }
public async Task <IActionResult> Create([Bind("id,MyProperty,results,baseUri,offset,number,totalRequests,processingTimeMs,expires,isStale")] SearchRecipes searchRecipes) { if (ModelState.IsValid) { _context.Add(searchRecipes); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(searchRecipes)); }
// GET: SearchRecipes public async Task <IActionResult> Index() { var client = new RestClient("https://spoonacular-recipe-food-nutrition-v1.p.rapidapi.com/recipes/search?diet=vegetarian&excludeIngredients=coconut&intolerances=egg%2C%20gluten&number=10&offset=0&type=main%20course&query=burger"); var request = new RestRequest(Method.GET); request.AddHeader("x-rapidapi-host", "spoonacular-recipe-food-nutrition-v1.p.rapidapi.com"); request.AddHeader("x-rapidapi-key", "f2216af4f5msh71430f2e651f9dap1350a2jsn801bc5c5aa5f"); IRestResponse response = client.Execute(request); var data = response.Content; SearchRecipes jsonResults = JsonConvert.DeserializeObject <SearchRecipes>(data); return(View(await _context.SearchRecipes.ToListAsync())); }
public static SearchRecipes CallSearchRecipeApi(string searchVal) { SearchRecipes objSearchRecipes = new SearchRecipes(); try { string query = "recipes?_app_id=" + ConfigurationManager.AppSettings["App_Id"] + "&_app_key=" + ConfigurationManager.AppSettings["App_Key"] + "&q=" + searchVal; string json = CallApiAL.CallWebApi(query); if (!String.IsNullOrEmpty(json)) { objSearchRecipes = JsonConvert.DeserializeObject <SearchRecipes>(json.ToString()); } } catch (Exception ex) { ex.SendMail(); objSearchRecipes = new SearchRecipes(); } return(objSearchRecipes); }
protected void CallGetRecipeApi() { try { SearchRecipes objSearchRecipe = new SearchRecipes(); objSearchRecipe = CallApiBL.CallSearchRecipeApi(searchVal); foreach (Matches mat in objSearchRecipe.matches) { if (mat.smallImageUrls != null && mat.smallImageUrls.Count > 0) { mat.smallImageUrl = mat.smallImageUrls[0]; } } rptRecipiesList.DataSource = objSearchRecipe.matches; rptRecipiesList.DataBind(); } catch (Exception ex) { ex.SendMail(); } }