Пример #1
0
        /// <summary>
        /// Adds an ingredient to the shopping list, in the group with the given name.
        /// </summary>
        /// <param name="ingredient">The ingredient.</param>
        /// <param name="groupName">Name of the group.</param>
        public void AddIngredientToShoppingList(Ingredient ingredient, String groupName)
        {
            ItemIngredient itemIngredient = ToolItem.CreateItemIngredient(ingredient);

            itemIngredient.Group = groupName;
            this.ShoppingList[groupName].Items.Add(itemIngredient);
            this.RefreshViews(new AddedIngredientEvent(this, ingredient, groupName));
        }
Пример #2
0
        /// <summary>
        /// Display all the ingredients of a receipe
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void ClickHandleIngredients(object sender, RoutedEventArgs e)
        {
            Button b = sender as Button;

            if (b != null && b.DataContext is ItemReceipe)
            {
                ItemReceipe item    = (ItemReceipe)b.DataContext;
                Receipe     receipe = item.Receipe;

                List <ItemIngredient> itemsIng = new List <ItemIngredient>();

                foreach (Ingredient ing in receipe.ingredients)
                {
                    itemsIng.Add(ToolItem.CreateItemIngredient(ing));
                }

                this.listIngredientsViewSource.Source = itemsIng;

                if (this.IngredientTextBlock != null)
                {
                    this.IngredientTextBlock.Text = (string)receipe.Title;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Fills the page with the previous elements while the navigation. Any state loaded is given when the page
        /// is recreated from a previous session.
        /// </summary>
        /// <param name="sender">
        /// The event source ; generaly <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e"> Event data that give the parameter of the navigation transmitted
        /// <see cref="Frame.Navigate(Type, Object)"/> during the initial request of this page and
        /// a state dictionnary preserved by this page during a previous session
        /// The state will not take the value Null when the first visit of this page.</param>
        private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            this.progressBar.Visibility = Visibility.Visible;
            this.Model          = (AppModel)e.NavigationParameter;
            this.receipe        = this.Model.SelectedReceipe;
            this.pageTitle.Text = receipe.Title;
            List <ItemReceipe>        receipeView        = new List <ItemReceipe>();
            List <ReceipeDescription> receipeDescription = new List <ReceipeDescription>();

            receipeDescription.Add(new ReceipeDescription(receipe));
            if (receipe.Id != -1)
            {
                ReceipeRetriever rr = new ReceipeRetriever();
                var task            = rr.extractReceipeFromMarmiton(receipe);
                var error           = false;
                try
                {
                    if ((await task) == true)
                    {
                        var task2 = rr.cleanHtmlEntities(receipe.HtmlReceipe, receipe);
                        rr.handleIngredients(rr.ingredientPart, receipe);

                        wb.NavigateToString(receipe.ToDoInstructions);
                    }
                }
                catch
                {
                    error = true;
                }
                if (error)
                {
                    var messageDialog = new MessageDialog("Une erreur est survenue ! Vous n'êtes pas connecté à Internet ou le serveur est indisponible.");
                    await messageDialog.ShowAsync();
                }
            }
            this.receipeViewSource.Source = receipeView;
            foreach (var ing in receipe.ingredients)
            {
                ingredients.Add(ToolItem.CreateItemIngredient(ing));
            }

            if (this.Model.FavouriteReceipes.ContainsKey(this.receipe.Title))
            {
                this.isFavourite = true;
            }
            else
            {
                this.isFavourite = false;
            }

            this.ingredientsViewSource.Source = ingredients;
            this.descriptionViewSource.Source = receipeDescription;
            this.RegisterForPrinting();

            this.descriptionHub.Visibility = Visibility.Visible;
            this.instructionsHub.Header    = "Instructions";
            this.imageEasyLifer.Visibility = Visibility.Collapsed;
            this.ingredientsHub.Visibility = Visibility.Visible;
            this.gestionHub.Visibility     = Visibility.Visible;
            this.progressBar.Visibility    = Visibility.Collapsed;
        }