public static RecipeInput[] FromChunkTypesArray(ChunkTypes[] source) { var buildup = new Dictionary <int, int>(); // Group identical chunks for (int i = 0; i < source.Length; i++) { int item = (int)source[i]; if (buildup.ContainsKey(item)) { buildup[item]++; } else { buildup.Add(item, 1); } } RecipeInput[] result = new RecipeInput[source.Length]; // Convert to RecipeInput array int inc = 0; foreach (var pair in buildup) { result[inc++] = new RecipeInput(pair.Key, pair.Value); } return(result); }
public ViewResult SaveReview(Review review) { review.RecipeID = Int32.Parse(Request.Form["RecipeID"]); reviewRepository.SaveReview(review); RecipeInput recipeInput = RecipeInput.convertIntoRecipeInput(review.RecipeID, recipeRepository, ingredientRepository, recipe_ingredientRepository, reviewRepository); return(View("DisplayPage", recipeInput)); }
public ViewResult AddRecipe(RecipeInput recipeInput) { Ingredient temp; Recipe recipe = new Recipe(); List <Ingredient> ingredients = new List <Ingredient>(); Recipe_Ingredient recipe_ingredient = new Recipe_Ingredient(); // transfers recipe information from recipeInput to a Recipe object to add in the repository later recipe.Title = recipeInput.Title; recipe.TotalTime = recipeInput.TotalTime; recipe.CookTime = recipeInput.CookTime; recipe.Instructions = recipeInput.Instructions; recipe.Category = recipeInput.Category; foreach (IngredientInput ingredient in recipeInput.Ingredients) // transfers ingredient names from recipeInput to an Ingredient list to add in the repository later { temp = new Ingredient(); temp.Name = ingredient.Name; ingredients.Add(temp); } recipeRepository.SaveRecipe(recipe); // Saves the recipe to the database ingredientRepository.SaveIngredients(ingredients); // Saves the ingredients to the database foreach (IngredientInput ingredient in recipeInput.Ingredients) // loads recipe_ingredient information to a recipe_ingredient object to add the database { try { recipe_ingredient.IngredientID = ingredientRepository.Ingredients .FirstOrDefault(i => i.Name == ingredient.Name).IngredientID; } catch (System.NullReferenceException) { continue; } recipe_ingredient.RecipeID = recipeRepository.RecipeList.Last().RecipeID; if (ingredient.UnitOfMeasurement == Recipe_Ingredient._unitOfMeasurement.atWill) { recipe_ingredient.Quantity = null; } else { recipe_ingredient.Quantity = ingredient.Quantity; } recipe_ingredient.UnitOfMeasurement = ingredient.UnitOfMeasurement; recipe_ingredientRepository.SaveRecipe_Ingredient(recipe_ingredient); } recipeInput.RecipeID = recipeRepository.RecipeList.FirstOrDefault(r => r.Title == recipeInput.Title).RecipeID; return(View("../Recipe/DisplayPage", recipeInput)); }
public ViewResult updateRecipe(RecipeInput recipeInput) { Ingredient temp; Recipe recipe = new Recipe(); List <Ingredient> ingredients = new List <Ingredient>(); Recipe_Ingredient recipe_ingredient = new Recipe_Ingredient(); // transfers recipe information from recipeInput to a Recipe object to update in the repository later recipeInput.RecipeID = Int32.Parse(Request.Form["RecipeID"]); recipe.RecipeID = recipeInput.RecipeID; recipe.Title = recipeInput.Title; recipe.TotalTime = recipeInput.TotalTime; recipe.CookTime = recipeInput.CookTime; recipe.Instructions = recipeInput.Instructions; recipe.Category = recipeInput.Category; foreach (IngredientInput ingredient in recipeInput.Ingredients) // transfers ingredient names from recipeInput to an Ingredient list to add in the repository later { temp = new Ingredient(); temp.Name = ingredient.Name; temp.IngredientID = ingredient.IngredientID; ingredients.Add(temp); } recipeRepository.SaveRecipe(recipe); // Saves the recipe to the database ingredientRepository.SaveIngredients(ingredients); // Saves the ingredients to the database if (!ingredients.Equals(recipeInput.Ingredients)) { foreach (IngredientInput ingredient in recipeInput.Ingredients) // loads recipe_ingredient information to a recipe_ingredient object to add in the database { recipe_ingredient = new Recipe_Ingredient(); recipe_ingredient.IngredientID = ingredient.IngredientID; recipe_ingredient.RecipeID = recipe.RecipeID; recipe_ingredient.Quantity = ingredient.Quantity; recipe_ingredient.UnitOfMeasurement = ingredient.UnitOfMeasurement; recipe_ingredientRepository.SaveRecipe_Ingredient(recipe_ingredient); } } return(View("../Recipe/DisplayPage", recipeInput)); }
[Route("Recipe/DisplayPage/{recipeID}")] //Attribute to receive the recipeID from the previous view public ViewResult DisplayPage(int recipeID) { RecipeInput recipeInput = RecipeInput.convertIntoRecipeInput(recipeID, recipeRepository, ingredientRepository, recipe_ingredientRepository, reviewRepository); return(View(recipeInput)); }
public virtual void RemoveRecipeInput(RecipeInput recipeInput) { RecipeInputs.Remove(recipeInput); recipeInput.Recipe = null; }
public virtual void AddRecipeInput(RecipeInput recipeInput) { RecipeInputs.Add(recipeInput); recipeInput.Recipe = this; }
public static void RegisterRecipe(ChunkTypes[] Inputs, int OutputID, string NameOfFabricator = "gsofab") { RegisterRecipe(RecipeInput.FromChunkTypesArray(Inputs), new RecipeOutput[] { new RecipeOutput(OutputID) }, NameOfFabricator: NameOfFabricator); }