Example #1
0
        public static List <Recipe> getAllRecipesFromJson()
        {
            List <Recipe> recipes = null;

            RelativeToAbsoluteConverter converter = new RelativeToAbsoluteConverter();
            String absolutePath = (String)converter.Convert(PATH, null, null, null);

            try
            {
                using (StreamReader r = new StreamReader(absolutePath))
                {
                    string jsonData = r.ReadToEnd();
                    recipes = JsonConvert.DeserializeObject <List <Recipe> >(jsonData);
                }

                //string jsonData = System.IO.File.ReadAllText(PATH);
            }
            catch (Exception ex)
            {
                recipes = null;
                Debug.WriteLine(ex.ToString());
            }

            return(recipes);
        }
Example #2
0
        public static void UpdateListRecipes(Recipe recipe)
        {
            List <Recipe> recipes = getAllRecipesFromJson();

            for (int i = 0; i < recipes.Count; ++i)
            {
                if (recipes[i].Name == recipe.Name)
                {
                    recipes[i] = recipe;

                    RelativeToAbsoluteConverter converter = new RelativeToAbsoluteConverter();
                    String absolutePath = (String)converter.Convert(PATH, null, null, null);

                    try
                    {
                        using (StreamWriter r = new StreamWriter(absolutePath))
                        {
                            string json = JsonConvert.SerializeObject(recipes, Formatting.Indented);
                            //System.IO.File.WriteAllText(PATH, json, Encoding.UTF8);
                            r.Write(json);
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.ToString());
                    }

                    break;
                }
            }
        }
Example #3
0
        private void ShowRecipeDetail()
        {
            isFavorite = this.SelectedRecipe.Favorite;
            favoriteIcon.Foreground = (isFavorite) ? Brushes.Red : Brushes.Gray;

            RecipeNameTextBlock.Text = this.SelectedRecipe.Name + "\n";
            if (this.SelectedRecipe.VideoLink != "")
            {
                YTlink.NavigateUri = new Uri(this.SelectedRecipe.VideoLink, UriKind.Absolute);
            }
            else
            {
                YTlink.Click += nullclickhandler;
            }

            foreach (String s in SelectedRecipe.Ingredients)
            {
                IngredientTextBlock.Text += s + "\n";
            }
            StepDescriptionTextBlock.Text = $"Bước {currentStep + 1}: " + SelectedRecipe.Step[currentStep].Description;
            try
            {
                RelativeToAbsoluteConverter converter = new RelativeToAbsoluteConverter();
                string imagePath = (SelectedRecipe.Step[currentStep].Images != "") ? SelectedRecipe.Step[currentStep].Images : SelectedRecipe.Avatar;

                String absolutePath = (String)converter.Convert(imagePath, null, null, null);
                var    image        = new BitmapImage(new Uri(absolutePath));
                StepImage.Source = image;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.StackTrace);
            }
        }
 public SplashWindow()
 {
     InitializeComponent();
     try
     {
         string imagePath = @"\Images\Background.jpg";
         RelativeToAbsoluteConverter converter = new RelativeToAbsoluteConverter();
         String absolutePath = (String)converter.Convert(imagePath, null, null, null);
         var    image        = new BitmapImage(new Uri(absolutePath));
         BackgroundImage.ImageSource = image;
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.StackTrace);
     }
 }
Example #5
0
        public MainWindow()
        {
            InitializeComponent();
            GridPrincipal.Children.Clear();
            boolSearch = 0;
            GridPrincipal.Children.Add(new Home());

            try
            {
                string imagePath = @"\Images\Background.jpg";
                RelativeToAbsoluteConverter converter = new RelativeToAbsoluteConverter();
                String absolutePath = (String)converter.Convert(imagePath, null, null, null);
                var    image        = new BitmapImage(new Uri(absolutePath));
                MenuImage.Source = image;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.StackTrace);
            }
        }
Example #6
0
        private void PreStep_Button_Click(object sender, RoutedEventArgs e)
        {
            if (currentStep > 0)
            {
                currentStep--;
                StepDescriptionTextBlock.Text = $"Bước {currentStep + 1}: " + SelectedRecipe.Step[currentStep].Description;

                try
                {
                    RelativeToAbsoluteConverter converter = new RelativeToAbsoluteConverter();
                    string imagePath = (SelectedRecipe.Step[currentStep].Images != "") ? SelectedRecipe.Step[currentStep].Images : SelectedRecipe.Avatar;

                    String absolutePath = (String)converter.Convert(imagePath, null, null, null);
                    var    image        = new BitmapImage(new Uri(absolutePath));
                    StepImage.Source = image;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.StackTrace);
                }
            }
        }