//private async void SaveButton_Click(object sender, RoutedEventArgs e) //{ // MealLog logger = null; // try // { // logger = new MealLog(); // string dietType = DietComboBox.SelectedValue.ToString(); // DietBase dietMeal = DietFactory.GetDietBase(dietType); // IDrink dietDrink = DietFactory.GetIDrink(dietType); // string meal = dietMeal.GetNextMeal(); // string drink = dietDrink.GetNextDrink(); // await logger.Log(DateTime.Now + " : " + meal + " : " + drink); // } // catch (Exception ex) // { // MessageBox.Show("Problem logging: " + ex.Message, "Error"); // } // finally // { // if (logger != null) // logger.Dispose(); // } //} private async void SaveButton_Click(object sender, RoutedEventArgs e) { using (var logger = new MealLog()) { string dietType = DietComboBox.SelectedValue.ToString(); DietBase dietMeal = DietFactory.GetDietBase(dietType); IDrink dietDrink = DietFactory.GetIDrink(dietType); string meal = dietMeal.GetNextMeal(); string drink = dietDrink.GetNextDrink(); await logger.Log(DateTime.Now + " : " + meal + " : " + drink); } }
private void DrinkButton_Click(object sender, RoutedEventArgs e) { try { string dietType = DietComboBox.SelectedValue.ToString(); IDrink diet = DietFactory.GetIDrink(dietType); string drink = diet.GetNextDrink(); MessageBox.Show("Next Drink: " + drink, "Drink"); } catch (ArgumentException ex) { MessageBox.Show("Please select a diet.", "Error"); } }
private void MealButton_Click(object sender, RoutedEventArgs e) { try { string dietType = DietComboBox.SelectedValue.ToString(); DietBase diet = DietFactory.GetDietBase(dietType); string meal = diet.GetNextMeal(); MessageBox.Show("Next Meal: " + meal, "Meal"); } catch (ArgumentException ex) { MessageBox.Show("Please select a diet.", "Error"); } }