private void GetRecipeUrl(HtmlDocument htmlDocument) { var items = _pageServices.GetHtml(htmlDocument, "div", "class", "listicle-item"); if (!items.Any()) { items = _pageServices.GetHtml(htmlDocument, "div", "class", "card-top"); } foreach (var item in items) { var link = item.Descendants("a").First(); var href = link.Attributes["href"].Value.Replace("/recipes", ""); var image = item.Descendants("img").First().Attributes["data-yo-src"].Value; var recipeHeader = new RecipeHeader { ImageUri = "http:" + image, RecipeUri = BaseUrl + href, Type = "Recipe", SurrogateId = int.Parse(href.Substring(href.LastIndexOf("-") + 1)) }; _recipeUrls.Add(recipeHeader); Console.WriteLine($"Recipe URL: {href}"); } }
public async Task <IActionResult> OnGetAsync(int?draftHeaderId) { if (!CheckPermissions()) { return(RedirectToPage(Url.Content("~/Home/Index"))); } if (draftHeaderId.HasValue) { RecipeHeader = await recipeRepository.GetRecipeHeader(draftHeaderId.Value); RecipeDetails = await recipeRepository.GetRecipeDetails(RecipeHeader.Id); DraftRecipeHeaderId = draftHeaderId.Value; } if (RecipeHeader is null) { RecipeHeader = new RecipeHeader { RecipeType = SmartCooking.Common.Enumeration.RecipeType.Draft }; await recipeRepository.InsertRecipeHeader(RecipeHeader); return(RedirectToPage("RecipeCreate", new { draftHeaderId = RecipeHeader.Id })); } RecipeImages = await recipeImageRepository.GetRecipeImages(draftHeaderId.Value); return(Page()); }
/// <summary> /// Διαγραφή του Object /// </summary> /// <param name="recipeHeader"></param> /// <returns></returns> public async Task <bool> DeleteRecipeHeader(RecipeHeader recipeHeader) { context.SC_RecipeHeader.Remove(recipeHeader); if (await context.SaveChangesAsync() <= 0) { return(false); } return(true); }
/// <summary> /// Προσθήκη Object /// </summary> /// <param name="recipeHeader"></param> /// <returns></returns> public async Task <bool> InsertRecipeHeader(RecipeHeader recipeHeader) { context.SC_RecipeHeader.Add(recipeHeader); if (await context.SaveChangesAsync() <= 0) { return(false); } return(true); }
private static void ConvertIngredients(List <HtmlNode> ingredients, RecipeHeader header) { foreach (var ingredient in ingredients) { var i = new Ingredients { RecipeHeaderId = header.Id, Ingredient = ingredient.InnerHtml.Trim() }; _ingredients.Add(i); } }
public static void AddIngredientsToDb(List <HtmlNode> ingredients, RecipeHeader header) { foreach (var ingredient in ingredients) { Console.WriteLine($"{ingredient.InnerHtml}"); Program.Context.Ingredients.Add(new Ingredients { RecipeHeaderId = header.Id, Ingredient = ingredient.InnerHtml }); } }
public async Task <IActionResult> OnPostDelete(int?recipeId) { if (!recipeId.HasValue) { HasError = true; ViewData["Error"] = "Δεν μπορείτε να περάσετε κενό ID."; return(Page()); } RecipeHeader dbRecipeHeader = await recipeRepository.GetRecipeHeader(recipeId.Value); if (dbRecipeHeader is null) { HasError = true; ViewData["Error"] = "Δεν υπάρχει εγγραφή με το ID που δόθηκε."; return(Page()); } IEnumerable <RecipeDetail> dbRecipeDetails = await recipeRepository.GetRecipeDetails(dbRecipeHeader.Id); foreach (RecipeDetail recipeDetail in dbRecipeDetails) { if (!await recipeRepository.DeleteRecipeDetail(recipeDetail)) { HasError = true; ViewData["Error"] = "Δεν μπορέσαμε να σβήσουμε την εγγραφή σας."; return(Page()); } } if (!await recipeRepository.DeleteRecipeHeader(dbRecipeHeader)) { HasError = true; ViewData["Error"] = "Δεν μπορέσαμε να σβήσουμε την εγγραφή σας."; return(Page()); } TempData["SuccessMessage"] = "Η διαγραφή του στοιχείου έγινε με επιτυχία."; return(RedirectToPage(Url.Content("~/Admin/RecipeList"))); }
private static void GetIngredients(string html, RecipeHeader header) { var htmlDocument = new HtmlDocument(); try { htmlDocument.LoadHtml(html); } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } var ingredientsList = GetIngredientsList(htmlDocument); var ingredients = new List <HtmlNode>(); if (!ingredientsList.Any()) { ingredientsList = GetIngredientsList2(htmlDocument); GetIngredientDetails2(ingredientsList, ingredients); } else { GetIngredientDetails(ingredientsList, ingredients); } if (!ingredientsList.Any()) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("No Ingredients Found"); Console.ForegroundColor = ConsoleColor.White; } ConvertIngredients(ingredients, header); }
public static RecipeHeader GetRecipeHeader(RecipeHeader recipeHeader) { return(Program.Context.RecipeHeaders.FirstOrDefault(x => x.SurrogateId == recipeHeader.SurrogateId)); }
public static void AddRecipeHeader(RecipeHeader recipeHeader) { Program.Context.RecipeHeaders.Add(recipeHeader); }