private async void loadRecipe(int id) { string page = Config.URL_JSON_ID + id; HttpClient client = new HttpClient(); HttpResponseMessage response = await client.GetAsync(page); HttpContent content = response.Content; string output = await content.ReadAsStringAsync(); if (output != null) { recipe = JsonConvert.DeserializeObject<Recipe>(output); } fillRectanglesWithColors(recipe.getCategoryInteger()); fillXamlElements(recipe); bool fileExists = await storageManager.createFile(); if(fileExists) { isFav = await storageManager.isFavorite(id); img_star.Source = (isFav) ? new BitmapImage() { UriSource = new Uri("ms-appx:///Assets/star_full.png", UriKind.Absolute) } : new BitmapImage() { UriSource = new Uri("ms-appx:///Assets/star_empty.png", UriKind.Absolute) }; } if (recipe.getImageString().Length != 0) { try { page = Config.URL_GALLERY + recipe.getImageString(); Stream st = await client.GetStreamAsync(page); var memoryStream = new MemoryStream(); await st.CopyToAsync(memoryStream); memoryStream.Position = 0; BitmapImage bitmap = new BitmapImage(); bitmap.SetSource(memoryStream.AsRandomAccessStream()); img_main.Source = bitmap; } catch (Exception e) { } } prog_recipe.IsActive = false; }
private async void btn_editor_preview_Click(object sender, RoutedEventArgs e) { if(checkFields()) { Recipe recipe = new Recipe(); recipe.title = tbx_title.Text; recipe.subtitle = tbx_subtitle.Text; //recipe.category = recipe.author = tbx_author.Text; recipe.ingredients = tbx_ingredients.Text; recipe.recipe = tbx_recipe.Text; recipe.preperationTime = tbx_preperationTime.Text; recipe.persons = persons; recipe.types = parseRecipeTypes(); await (new MessageDialog(recipe.getJSON())).ShowAsync(); } }
private void fillXamlElements(Recipe recipe) { lbl_title.Text = recipe.getTitle(); lbl_subtitle.Text = recipe.getSubtitle(); lbl_recipe.Text = recipe.getRecipe(); lbl_type.Text = recipe.getRecipeType(); lbl_rect_left.Text = recipe.getPersons() + " personen"; lbl_rect_middle.Text = recipe.getPreperationTime(); lbl_rect_right.Text = recipe.getAuthor(); string[] ingredients = recipe.getIngredients(); string output_left = ""; string output_right = ""; for (int x = 0; x < 10 && x < ingredients.Length; x++) { if (x < 5) output_left += ingredients[x].Trim() + "\n"; else output_right += ingredients[x].Trim() + "\n"; } lbl_ingredients_left.Text = output_left; lbl_ingredients_right.Text = output_right; if (recipe.getTip().Length != 0) { lbl_tip_title_low.Text = "Tip:"; lbl_tip_low.Text = recipe.getTip(); img_tip_low.Source = new BitmapImage(new Uri("ms-appx:///Assets/tip.png")); if (recipe.getWineTip().Length != 0) { lbl_tip_title_top.Text = "Wijntip:"; lbl_tip_top.Text = recipe.getWineTip(); img_tip_top.Source = new BitmapImage(new Uri("ms-appx:///Assets/wine.png")); } } else if (recipe.getWineTip().Length != 0) { lbl_tip_title_low.Text = "Wijntip:"; lbl_tip_low.Text = recipe.getWineTip(); img_tip_low.Source = new BitmapImage(new Uri("ms-appx:///Assets/wine.png")); } }