//Creates an addEditRecipeViewModel from a recipe class constructor //For edit view public static AddEditRecipeViewModel ConvertToViewModel(IList <Ingredient> recipe) { IList <int> ingredientID = new List <int>(); IList <string> ingredientName = new List <string>(); foreach (Ingredient ingredient in recipe) { ingredientID.Add(ingredient.ID); ingredientName.Add(ingredient.Name); } //Put it all in the ViewModel AddEditRecipeViewModel viewModel = new AddEditRecipeViewModel { ID = recipe[0].RecipeID, Title = recipe[0].Recipe.Title, Description = recipe[0].Recipe.Description, Type = recipe[0].Recipe.Type, Time = recipe[0].Recipe.Time, Serve = recipe[0].Recipe.Serve, Source = recipe[0].Recipe.Source, IngredientsID = ingredientID, IngredientsName = ingredientName }; return(viewModel); }
/// <summary> /// For http post request from an edit form /// </summary> /// <param name="addEditRecipeViewModel"></param> /// <returns>recipe object</returns> public static Recipe CreateRecipe(AddEditRecipeViewModel addEditRecipeViewModel) { Recipe newrecipe = new Recipe { ID = addEditRecipeViewModel.ID, Title = addEditRecipeViewModel.Title, Description = addEditRecipeViewModel.Description, Type = addEditRecipeViewModel.Type, Time = (int)addEditRecipeViewModel.Time, Serve = addEditRecipeViewModel.Serve, Source = addEditRecipeViewModel.Source }; return(newrecipe); }