public IActionResult List(int tagid, int start = 0) { var recipes = _ramseyContext.RecipeTags .Where(x => x.TagId == tagid) .Include(x => x.Recipe) .Select(x => x.Recipe) .OrderBy(x => x.Name) .Skip(start) .Take(25); var dtos = new List <RecipeMetaDtoV2>(); foreach (var recipe in recipes) { var dto = new RecipeMetaDtoV2(); dto.Image = recipe.Image; dto.Name = recipe.Name; dto.Source = recipe.Source; dto.OwnerLogo = recipe.OwnerLogo; dto.Owner = recipe.Owner; dto.RecipeId = recipe.RecipeId; dtos.Add(dto); } return(Json(dtos)); }
public static bool RecipeMetaExistsInList(RecipeMetaDtoV2 recipe, List <RecipeMetaDtoV2> recipeList) { foreach (var r in recipeList) { if (recipe.RecipeID == r.RecipeID) { return(true); } } return(false); }
public RecipePage(RecipeMetaDtoV2 recipeMeta) { InitializeComponent(); BindingContext = this; fromSavedRecipes = false; this.recipeMeta = recipeMeta; myIngredients = User.User.SavedIngredinets; XamlSetup1(); GET_recipeDto(recipeMeta.RecipeID); Task.Factory.StartNew(() => UpdateFavorite()); }
//Next page async void GotoRecipePage(RecipeMetaDtoV2 recipeMeta) { await Navigation.PushAsync(new RecipePage(recipeMeta) { Title = recipeMeta.Name }); canOpenNewRecipes = true; }
public async Task <bool> UpdateRecipeMetaAsync(RecipeMetaDtoV2 recipeMetaDto) { var stopWatch = new Stopwatch(); stopWatch.Start(); var recipe = _context.Recipes.AddIfNotExists(new RecipeMeta { RecipeId = recipeMetaDto.RecipeId, }, x => x.RecipeId == recipeMetaDto.RecipeId); await SaveRecipeChangesAsync(); //Basic Properties recipe.Image = recipeMetaDto.Image; recipe.Name = recipeMetaDto.Name; recipe.Owner = recipeMetaDto.Owner; recipe.OwnerLogo = recipeMetaDto.OwnerLogo; recipe.Rating = 0; recipe.Source = recipeMetaDto.Source; //Ingredients foreach (var partDto in recipeMetaDto.RecipeParts) { if (string.IsNullOrEmpty(partDto.IngredientName)) { continue; } string ingredientName = partDto.IngredientName; string recipeId = recipeMetaDto.RecipeId; var ingredient = _context.Ingredients.AddIfNotExists(new Ingredient { IngredientName = ingredientName }, x => x.IngredientName == ingredientName); await SaveRecipeChangesAsync(); var part = _context.RecipeParts.AddIfNotExists(new RecipePart { RecipeId = recipeId, IngredientId = ingredient.IngredientId }, x => x.RecipeId == recipeId && x.Ingredient.IngredientName == ingredientName); await SaveRecipeChangesAsync(); part.IngredientId = ingredient.IngredientId; part.Recipe = recipe; part.Quantity = partDto.Quantity; part.Unit = partDto.Unit; _context.RecipeParts.Update(part); await SaveRecipeChangesAsync(); recipe.RecipeParts.Add(part); } //Tags foreach (var tagDto in recipeMetaDto.Tags) { var tag = _context.Tags.AddIfNotExists(new Core.Models.Tag { Name = tagDto.Name, }, x => x.Name == tagDto.Name); await _context.SaveChangesAsync(); _context.RecipeTags.AddIfNotExists(new Core.Models.RecipeTag { RecipeId = recipe.RecipeId, TagId = tag.TagId }, x => x.TagId == tag.TagId && x.Recipe.RecipeId == recipe.RecipeId); await _context.SaveChangesAsync(); } _context.Recipes.Update(recipe); await SaveRecipeChangesAsync(); stopWatch.Stop(); Debug.WriteLine("Recipe {0} took {1} ms to reload.", recipe.Name, stopWatch.Elapsed.Milliseconds); return(true); }