예제 #1
0
        private void SaveSet_Button_Click(object sender, RoutedEventArgs e)
        {
            if (AreListsEmpty())
            {
                return;
            }

            string name        = SetName.Text;
            string description = SetDescription.Text;

            if (name.Trim().Equals("") || description.Trim().Equals(""))
            {
                MessageBox.Show("You must provide a name and description of set!");
                return;
            }

            Diet diet = new Diet(name, description);

            for (int i = 0; i < breakfastProductsList.Items.Count; i++)
            {
                diet.AddProduct((DietProduct)breakfastProductsList.Items[i]);
            }

            for (int i = 0; i < lunchProductsList.Items.Count; i++)
            {
                diet.AddProduct((DietProduct)lunchProductsList.Items[i]);
            }

            for (int i = 0; i < dinnerProductsList.Items.Count; i++)
            {
                diet.AddProduct((DietProduct)dinnerProductsList.Items[i]);
            }

            IDietsProvider provider = new XMLDietsParser();

            provider.AddDiet(diet);

            MessageBox.Show("Set saved!");

            breakfastProductsList.Items.Clear();
            lunchProductsList.Items.Clear();
            dinnerProductsList.Items.Clear();
        }