public AddEditRecipe(RecipeViewModel recipeView) { InitializeComponent(); _recipeView = recipeView; _recipe = recipeView.GetRecipe(); listOfIngredientsDataGridView.DataSource = Globals.AllIngredients; recipeIngredientsDataGridView.DataSource = IngredientsInRecipeView; Globals.GetIngredientsInRecipe(_recipe.Id).ForEach(ibr => IngredientsInRecipeView.Add(new IngredientByRecipeViewModel(ibr))); categoryComboBox.Items.AddRange(categoryList); titleTextBox.Text = _recipe.Title; categoryComboBox.SelectedItem = _recipe.Category; instructionsTextBox.Text = _recipe.Instructions; if (_recipe.GetType() == typeof(PersonalRecipe)) { var personalRecipe = (PersonalRecipe)_recipe; personalTypeRadioButton.Checked = true; secretCheckBox.Checked = personalRecipe.Secret; } if (_recipe.GetType() == typeof(WebRecipe)) { var webRecipe = (WebRecipe)_recipe; webTypeRadioButton.Checked = true; typeATextBox.Text = webRecipe.Url; } if (_recipe.GetType() == typeof(BookRecipe)) { var bookRecipe = (BookRecipe)_recipe; bookTypeRadioButton.Checked = true; typeATextBox.Text = bookRecipe.BookTitle; typeBTextBox.Text = bookRecipe.BookAuthor; } }
public void RecipeViewModelWillReturnRecipeWhenGetRecipeCalled() { //Arrange var expected = new WebRecipe(); var recipeView = new RecipeViewModel(expected); //Act var actual = recipeView.GetRecipe(); //Assert Assert.AreEqual(expected, actual); }
public static void UpdateRecipe(List <IngredientByRecipe> ingredientByRecipeList, Recipe recipe, RecipeViewModel recipeView) { var originalRecipe = recipeView.GetRecipe(); var database = new SQLiteDataService(); database.Initialize(); database.UpdateRecipe(recipe); database.DeleteIngredientsByRecipe(originalRecipe.Id); ingredientByRecipeList.ForEach(ibr => { ibr.RecipeId = originalRecipe.Id; database.AddIngredientByRecipe(ibr); }); database.Close(); var allUsersRecipesList = AllUsersRecipes.ToList(); AllUsersRecipes.Clear(); var index = allUsersRecipesList.IndexOf(recipeView); allUsersRecipesList.RemoveAt(index); allUsersRecipesList.Insert(index, new RecipeViewModel(recipe)); allUsersRecipesList.ForEach(rVM => AllUsersRecipes.Add(rVM)); }