コード例 #1
0
 public RecipeViewModel(Recipe recipe)
 {
     this.Title = recipe.Title;
     this.Time = recipe.Time;
     this.PreparationWay = recipe.PreparationWay;
     this.Ingredients = recipe.Ingredients;
     this.ImageURL = recipe.ImageURL;
 }
コード例 #2
0
 public FavouriteRecipe(Recipe recipe)
 {
     this.Time = recipe.Time;
     this.Title = recipe.Title;
     this.Ingredients = recipe.Ingredients;
     this.PreparationWay = recipe.PreparationWay;
     this.ImageURL = recipe.ImageURL;
     this.AddingDate = DateTime.Now;
 }
コード例 #3
0
        public Recipe ConvertIntoRecipe()
        {
            Recipe newRecipe = new Recipe();
            newRecipe.Title = this.Title;
            newRecipe.Time = this.Time;
            newRecipe.PreparationWay = this.PreparationWay;
            newRecipe.Ingredients = this.Ingredients;
            newRecipe.ImageURL = this.ImageURL;

            return newRecipe;
        }
コード例 #4
0
        public static async Task<List<Recipe>> GetAllRecepiesFromHttpRequest()
        {
            List<Recipe> recipes = new List<Recipe>();
            string url = "http://www.bonapeti.bg/recepti/";

            var htmlDoc = new HtmlAgilityPack.HtmlDocument
            {
                OptionFixNestedTags = true,
                OptionAutoCloseOnEnd = true
            };

            var recHtmlDoc = new HtmlAgilityPack.HtmlDocument
            {
                OptionFixNestedTags = true,
                OptionAutoCloseOnEnd = true
            };

            for (int i = 1; i <= 3; i++)
            {
                string data = await GetResponseString(url + "?page=" + i);
                htmlDoc.LoadHtml(data);

                var titles = htmlDoc.DocumentNode.DescendantsAndSelf("a").Where(x => x.Attributes["title"] != null && x.ChildNodes.Count > 1
                    && x.Attributes["class"].Value.Contains("recipe_link"));

                var imageUrls = htmlDoc.DocumentNode.Descendants("div").Where(x => x.Attributes["class"] != null 
                    && (x.Attributes["class"].Value == "recipe_container" || x.Attributes["class"].Value == "user_recipe_container"));

                Recipe recipe = new Recipe();

                foreach (var imgUrl in imageUrls)
                {
                    if(imgUrl.InnerHtml.Contains("<img "))
                    {
                        string value = imgUrl.InnerHtml.Substring(imgUrl.InnerHtml.IndexOf("src=\""), 
                            imgUrl.InnerHtml.IndexOf("\" width") - imgUrl.InnerHtml.IndexOf("src=\"")).Replace("src=\"", "");
                        imageURLs.Add(value);
                    }
                    else
                    {
                        imageURLs.Add("http://www.bonapeti.bg/images/user_nodish_big.jpg");
                    }
                }

                foreach (var title in titles)
                {
                    recipe = new Recipe();
                    recipe.Title = title.Attributes["title"].Value;
                    string recipeLink = title.Attributes["href"].Value;

                    string recData = await GetResponseString(recipeLink);
                    recHtmlDoc.LoadHtml(recData);
                    var timeNode = recHtmlDoc.DocumentNode.Descendants("div").Where(x => x.Attributes["itemprop"] 
                        != null && x.Attributes["itemprop"].Value == "cookTime"); //or SelectSingleNode("//*[@id=\"printable_area\"]/div[4]/div[1]/div[2]");
                    foreach (var time in timeNode)
                    {
                        recipe.Time = time.InnerText.Trim();
                        break;
                    }
                    var ingredients = recHtmlDoc.DocumentNode.Descendants("table").Where(x => x.Attributes["class"] != null 
                        && x.Attributes["class"].Value == "tbl_products");           //or ("//*[contains(@class,'last')]");
                    string ingredientsText = "";
                    foreach (var ingr in ingredients)
                    {
                        ingredientsText += ingr.InnerHtml.Trim();
                    }
                    recipe.Ingredients = ingredientsText.Replace("&nbsp;", "\n").
                                            Replace("\t", "").
                                            Replace("\n", "").
                                            Replace("<tr>", "").
                                            Replace("</tr>", "").
                                            Replace("<td class=\"last\">", "").
                                            Replace("<td class=\"last\" colspan=\"1\">", "").
                                            Replace("<td class=\"last\" colspan=\"2\">", "").
                                            Replace("<td class=\"last\" colspan=\"3\">", "").
                                            Replace("<td>", "").
                                            Replace("</td>", "").
                                            Replace("<br>", "\n").
                                            Replace("<span itemprop=\"ingredients\">", "").
                                            Replace("</span>", "").
                                            Replace("<b>", "\n").
                                            Replace("</b>", "").
                                            Replace("\n ", "\n").
                                            TrimEnd().TrimStart(',');

                    var preparations = recHtmlDoc.DocumentNode.Descendants("td").Where(x => x.Attributes["class"] != null 
                        && x.Attributes["class"].Value == "stepDescription");  //or ("//*[contains(@class,'stepDescription')]");
                    StringBuilder prepWay = new StringBuilder();
                    foreach (var prep in preparations)
                    {
                        prepWay.Append(prep.InnerText.Trim());
                    }
                    recipe.PreparationWay = prepWay.ToString();

                    recipes.Add(recipe);
                }
            }
            for (int j = 0; j < recipes.Count; j++)
            {
                if (j < imageURLs.Count)
                {
                    recipes[j].ImageURL = imageURLs[j];
                }
                else
                {
                    recipes[j].ImageURL = "http://www.bonapeti.bg/images/user_nodish_big.jpg";
                }
                
            }


            return recipes;
        }
コード例 #5
0
        private async void submitButton_Click(object sender, RoutedEventArgs e)
        {
            Recipe currentRecipe = new Recipe();
            currentRecipe.Title = this.titleextBox.Text;
            currentRecipe.Time = this.timeTextBox.Text;
            currentRecipe.Ingredients = this.ingredientsTextBox.Text;
            currentRecipe.PreparationWay = this.descriptionTextBox.Text;
            if (photoPlaceholder == null)
            {
                currentRecipe.ImageURL = "http://www.bonapeti.bg/images/user_nodish_big.jpg";
            }
            else
            {
                currentRecipe.ImageURL = newPicturePath;
            }            

            bool dbExists = await CheckDbAsync(dbName);
            SQLiteAsyncConnection conn = new SQLiteAsyncConnection(dbName);

            if (!dbExists)
            {
                await conn.CreateTableAsync<Recipe>();
            }
            await conn.InsertAsync(currentRecipe);

            
            SQLiteAsyncConnection baseConn = new SQLiteAsyncConnection(baseDbName);
            await baseConn.InsertAsync(currentRecipe);

            SendNotification("Database info", "The recipe was added", "ïnto your own list", "/Images/star.png");
        }