Esempio n. 1
0
        private void BtnAddToLookup_Click(object sender, RoutedEventArgs e)
        {
            bool          success = false;
            List <string> validateResults;

            ingredients.Ingredient = new Ingredient
            {
                Name = TbIngredient.Text
            };

            validateResults = ingredients.Validate(ingredients.Ingredient);

            if (validateResults.Count == 0)
            {
                success = ingredients.Add(ingredients.Ingredient);
            }

            if (success)
            {
                ClearNewIngredient();
                RefreshIngredients();
                LbIngredients.SelectedItem = ingredients.Ingredient;
                LbIngredients.ScrollIntoView(LbIngredients.SelectedItem);

                ;
            }
            else
            {
                MessageBox.Show("There are problems with your ingredient:\r\n" + string.Join("\r\n", validateResults.ToArray()), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            bool          success = false;
            List <string> validateResults;

            // Add ingredient
            if (Ingredients.Current == null)
            {
                Ingredient newIngredient = new Ingredient
                {
                    Name = TbIngredient.Text
                };
                validateResults = Ingredients.Validate(newIngredient);

                if (validateResults.Count == 0)
                {
                    success = Ingredients.Add(newIngredient);
                }
            }
            else
            {
                Ingredients.Current.Name = TbIngredient.Text;
                validateResults          = Ingredients.Validate(Ingredients.Current);

                if (validateResults.Count == 0)
                {
                    success = Ingredients.Edit(Ingredients.Current);
                }
            }

            if (success)
            {
                Clear();
                Refresh();

                MessageBox.Show(
                    "Ingredient added!",
                    "Success",
                    MessageBoxButton.OK,
                    MessageBoxImage.Information
                    );
            }
            else
            {
                MessageBox.Show("There are problems with your ingredient:\r\n" + string.Join("\r\n", validateResults.ToArray()), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 3
0
 public void AddIngredients(string Ingredient)
 {
     Ingredients.Add(Ingredient);
 }