private void SetAllRecipesCreationPrice() { foreach (var recipe in _repo.GetAllRecipes().ToList()) { List <Ingredient> allIngredients = recipe.Ingredients; if (recipe.GuildIngredients != null) { allIngredients.AddRange(recipe.GuildIngredients); } List <TPListing> itemListings = _repo.GetItemBuyOrder(recipe.OutputItemId); RecipePrice recipePrice = new RecipePrice(); recipePrice.ItemId = recipe.OutputItemId; int?itemPrice; if (itemListings == null || itemListings.Count == 0) { itemPrice = null; recipePrice.PossibleToBuy = false; continue; } itemPrice = (int)(itemListings[0].UnitPrice * 0.85); int?creationPriceBuyNow = 0; int?creationPriceBuyOrder = 0; foreach (var ingredient in allIngredients) { List <TPListing> ingredientListings = _repo.GetItemSellOrder(ingredient.ItemId); int?ingredientPrice = GetItemIngredientPrice(ingredient, ingredientListings); if (ingredientPrice == null) { creationPriceBuyNow = null; } else if (creationPriceBuyNow != null) { creationPriceBuyNow += ingredientPrice; } ingredientListings = _repo.GetItemBuyOrder(ingredient.ItemId); ingredientPrice = GetItemIngredientPrice(ingredient, ingredientListings); if (ingredientPrice == null) { creationPriceBuyOrder = null; } else if (creationPriceBuyOrder != null) { creationPriceBuyOrder += ingredientPrice; } } if (creationPriceBuyNow != null) { recipePrice.CreationPriceBuyNow = itemPrice.Value - creationPriceBuyNow.Value; } if (creationPriceBuyOrder != null) { recipePrice.CreationPriceBuyOrder = itemPrice.Value - creationPriceBuyOrder.Value; } if (creationPriceBuyOrder == null && creationPriceBuyNow == null) { recipePrice.PossibleToBuy = false; } else { recipePrice.PossibleToBuy = true; } if (recipePrice.PossibleToBuy) { _repo.AddRecipePrice(recipePrice); } } }