protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            Type type = e.Parameter.GetType();
            TotalAmountUOMTextBox.ItemsSource = _unitOfMeasureList;

            if (type == typeof(FoodCategoryViewModel))
            {
                FoodCategoryViewModel category = (FoodCategoryViewModel)e.Parameter;
                CategoryTextBox.Text = category.Name;
                CategoryTextBox.IsReadOnly = true;
                _existingMealItem = new MealItemViewModel();
                _existingMealItem.Category = category.Name;
            }
            else if (type == typeof(MealItemViewModel))
            {
                _existingMealItem = (MealItemViewModel)e.Parameter;
                CategoryTextBox.Text = _existingMealItem.Category;
                CategoryTextBox.IsReadOnly = true;
                NameTextBox.Text = _existingMealItem.Name;
                NameTextBox.IsReadOnly = true;
                ingredientsViewModel = new IngredientsViewModel();
                _selectedIngredientsList = ingredientsViewModel.GetIngredients(_existingMealItem.IngredientIDsWithTotalAmount);
                TotalAmountTextBox.Text = _existingMealItem.TotalAmount.ToString();
                TotalAmountUOMTextBox.SelectedIndex = _existingMealItem.TotalAmountUnitOfMeasure-1;

                var copy = new ObservableCollection<IngredientViewModel>(_selectedIngredientsList);
                foreach (var ingredient in copy)
                {
                    FindAndRemoveIngredient(_allIngredients, ingredient);
                }
            }

            AllIngredientsList.ItemsSource = _allIngredients;
            SelectedIngredientsList.ItemsSource = _selectedIngredientsList;           
        }
        public NewMealItem()
        {
            this.InitializeComponent();

            IngredientsViewModel ingredientsViewModel = new IngredientsViewModel();
            _allIngredients = ingredientsViewModel.GetAllIngredients();
            _selectedIngredientsList = new ObservableCollection<IngredientViewModel>();
            UnitsOfMeasureViewModel unitsOfMeasureViewModel = new UnitsOfMeasureViewModel();
            _unitOfMeasureList = unitsOfMeasureViewModel.GetUnitsOfMeasure();
            this.DataContext = this;
        }
        private string GetIngredientsAsText(IngredientsViewModel ingredientsView, 
            MealItemViewModel mealItem, Dictionary<float,float> mealItemIDsWithWeight)
        {
            StringBuilder sb = new StringBuilder();
            ObservableCollection<IngredientViewModel> ingredients =
                    ingredientsView.GetIngredients(mealItem.IngredientIDsWithTotalAmount);

            if (ingredients.Count > 0)
            {
                //sb.Append(@"\b ");
                int loopCount = 0;
                UnitOfMeasureViewModel unitOfMeasure = new UnitOfMeasureViewModel();
                MealItemViewModel defaultMealItem = new MealItemViewModel();
                defaultMealItem = defaultMealItem.GetMealItemById(mealItem.Id);

                foreach (var ingredient in ingredients)
                {
                    float ingredientDefaultWeight = mealItem.IngredientIDsWithTotalAmount[ingredient.Id];
                    if (defaultMealItem.TotalAmount == 0) defaultMealItem.TotalAmount = 1;
                    float ingredientWeight = (ingredientDefaultWeight / defaultMealItem.TotalAmount) * mealItemIDsWithWeight[mealItem.Id];
                    decimal roundedIngredientWeight = Math.Round((decimal)ingredientWeight, 0);
                    string uomName = unitOfMeasure.GetUnitOfMeasure(ingredient.UnitOfMeasure).Abbreviation;
                    sb.Append(roundedIngredientWeight.ToString());
                    sb.Append(uomName).Append(" ");
                    sb.Append(ingredient.Name);

                    if ((ingredients.Count >1) && (loopCount < (ingredients.Count-1)))
                    { sb.Append(", "); }

                    loopCount++;
                }

                //sb.Append(@"\line\b0");
                sb.Append(@"\line");
                return sb.ToString();
            }
            else
                return "";
        }
        private void MealItemsListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            IngredientsListView.ItemsSource = null;
            IngredientsListView.Items.Clear();

            MealItemViewModel mealItem = null;
            mealItem = (MealItemViewModel)MealItemsGridView.SelectedItem;

            if (mealItem != null)
            {
                ingredientsViewModel = new IngredientsViewModel();
                ObservableCollection<IngredientViewModel> ingredients = ingredientsViewModel.GetIngredients(mealItem.IngredientIDsWithTotalAmount);
                IngredientsListView.ItemsSource = ingredients;
            }
        }
        public string GetTextRepresentation(IMealViewModel meal)
        {
            StringBuilder result = new StringBuilder();
            MealItemsViewModel mealItemsView = new MealItemsViewModel();
            IngredientsViewModel ingredientsView = new IngredientsViewModel();
            ContactViewModel contact = new ContactViewModel();
            contact = contact.GetContact(meal.ContactId);
            string tmp = contact.NameAndAddress;
            tmp = tmp.Replace('\n', '|');
            tmp = tmp.Replace('\r', '|');
            string nameAndAddress = tmp.Replace("||", "\\line ");
            nameAndAddress = contact.Attention + "\\line " + tmp.Replace("||", "\\line ");

            result.Append(@"{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Calibri;}{\f1\fnil\fcharset0 Calibri;}}");
            result.Append(@"{\*\generator Riched20 10.0.10240}\viewkind4\uc1\pard\tx720\cf1\f0\fs22\lang1031\line\line\line\f1\fs26");
            result.Append(" Lieferschein Nr. ").Append(meal.DeliveryNoteId).Append(@"\line \line "); ;
            result.Append(nameAndAddress).Append(@" \line ");
            result.Append("Tel. Nr. : ").Append(contact.PhoneNr).Append(@" \line ");
            result.Append("Handy Nr. : ").Append(contact.CellPhoneNr).Append(@" \line \line ");
            result.Append("Veranstaltungsort:").Append(@" \line ");
            result.Append(meal.DeliveryLocation).Append(@" \line \line ");
            result.Append("Ihr Ansprechpartner: ").Append(@" \line \line ");
            result.Append(_dateTimeConverter.Convert(meal.DeliveryDate, null, null, "")).Append("  ");
            result.Append(_timeSpanConverter.Convert(meal.DeliveryTime,null,null,"")).Append("  Uhr Buffetbeginn").Append(@"\line \line \line");
            result.Append(@" \highlight2 ");
            result.Append("Erwachsene: ").Append(meal.NumberOfGuests).Append(@"\line \line ");
            result.Append(@" \highlight0 ");

            ObservableCollection<MealItemViewModel> _mealItems =
                mealItemsView.GetMealItems(meal.MealItemIDsWithWeight);

            foreach (var mealItem in _mealItems)
            {
                float mealItemWeight = meal.MealItemIDsWithWeight[mealItem.Id];
                result.Append(@"\b ");
                result.Append(mealItem.Name.ToString()).Append("   ");

                UnitOfMeasureViewModel unitOfMeasure = new UnitOfMeasureViewModel();
                string unitOfMeasureName = unitOfMeasure.GetUnitOfMeasure(mealItem.TotalAmountUnitOfMeasure).UnitName;
                string unitOfMeasureAbbreviation = unitOfMeasure.GetUnitOfMeasure(mealItem.TotalAmountUnitOfMeasure).Abbreviation;

                result.Append(mealItemWeight.ToString()).Append("").Append(unitOfMeasureAbbreviation);
                result.Append(@"\line\b0 ");
                result.Append(GetIngredientsAsText(ingredientsView, mealItem, meal.MealItemIDsWithWeight));
                result.Append(@" \line ");
            }

            result.Append(@" \line }");

            return result.ToString();
        }