protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.Parameter != null)
            {
                _meal = (IMealViewModel)e.Parameter;

                if (_meal is MealViewModel)
                {
                    _backNavigationTarget = typeof(MealItems);
                }
                else if (_meal is MealSuggestionViewModel)
                {
                    _backNavigationTarget = typeof(MealSuggestions);
                }
            }
        }
        public string RemoveMealItem(IMealViewModel mealSuggestion, int mealItemID)
        {
            string result = string.Empty;

            mealSuggestion.MealItemIDsWithWeight.Remove(mealItemID);
            result = mealSuggestion.SaveMeal(mealSuggestion);

            return result;
        }
        public string SaveMeal(IMealViewModel mealSuggestion)
        {
            string result = string.Empty;
            using (var db = new SQLite.SQLiteConnection(App.DBPath))
            {
                string change = string.Empty;
                try
                {
                    var existingMealSuggestion = (db.Table<MealSuggestion>().Where(
                        c => c.Id == mealSuggestion.Id)).SingleOrDefault();

                    if (existingMealSuggestion != null)
                    {
                        existingMealSuggestion.CategoryId = mealSuggestion.CategoryId;
                        existingMealSuggestion.MealItemIDsWithWeight =
                            (byte[])_dictionaryConverterFloat.Convert(mealSuggestion.MealItemIDsWithWeight, null, null, "");

                        int success = db.Update(existingMealSuggestion);
                    }
                    else
                    {
                        int success = db.Insert(new MealSuggestion()
                        {
                            CategoryId = mealSuggestion.CategoryId,
                            MealItemIDsWithWeight =
                                (byte[])_dictionaryConverterFloat.Convert(mealSuggestion.MealItemIDsWithWeight, null, null, "")
                        });

                        SQLiteCommand cmd = db.CreateCommand("SELECT last_insert_rowid()");
                        int rowId = cmd.ExecuteScalar<int>();
                        cmd.CommandText = "SELECT Id FROM MealSuggestion WHERE rowid = " + rowId.ToString();
                        mealSuggestion.Id = cmd.ExecuteScalar<int>();
                    }
                    result = "Success";
                }
                catch
                {
                    result = "This meal suggestion was not saved.";
                }
            }

            return result;
        }
 string IMealViewModel.GetTextRepresentation(IMealViewModel meal)
 {
     throw new NotImplementedException();
 }
        public string AddMealItem(IMealViewModel mealSuggestion, int mealItemID, float mealItemWeight)
        {
            string result = string.Empty;
            float foundMealItemWeight = -1;

            if (!mealSuggestion.MealItemIDsWithWeight.TryGetValue(mealItemID, out foundMealItemWeight))
            {
                mealSuggestion.MealItemIDsWithWeight.Add(mealItemID, mealItemWeight);
                result = mealSuggestion.SaveMeal(mealSuggestion);
            }
            else
            {
                result = "Meal Item already exits";
            }

            return result;
        }
        public string SetDefaultMealItemWeights(IMealViewModel meal)
        {
            string result = "";
            MealItemViewModel mealItem = new MealItemViewModel();

            foreach (var mealItemKeyValue in meal.MealItemIDsWithWeight.ToList())
            {
                mealItem = mealItem.GetMealItemById((int)mealItemKeyValue.Key);
                float mealItemWeightDefault = mealItem.TotalAmount;
                float totalWeight = mealItemWeightDefault * meal.NumberOfGuests;
                meal.MealItemIDsWithWeight[mealItemKeyValue.Key] = totalWeight;
            }

            return result;
        }
        public string SaveMeal(IMealViewModel meal)
        {
            string result = string.Empty;
            using (var db = new SQLite.SQLiteConnection(App.DBPath))
            {
                string change = string.Empty;
                try
                {
                    var existingMeal = (db.Table<Meal>().Where(
                        c => c.Id == meal.Id)).SingleOrDefault();

                    if (existingMeal != null)
                    {
                        existingMeal.DeliveryNoteId = meal.DeliveryNoteId;
                        existingMeal.Name = meal.Name;
                        existingMeal.DeliveryDate = meal.DeliveryDate;
                        existingMeal.DeliveryTime = meal.DeliveryTime;
                        existingMeal.DeliveryLocation = meal.DeliveryLocation;
                        existingMeal.PickupDate = meal.PickupDate;
                        existingMeal.Contact = meal.Contact;
                        existingMeal.ContactId = meal.ContactId;
                        existingMeal.NumberOfGuests = meal.NumberOfGuests;
                        existingMeal.SilverWare = meal.SilverWare;
                        existingMeal.MealItemIDs = (byte[])_converter.Convert(meal.MealItemIDs, null, null, "");
                        existingMeal.MealItemIDsWithWeight =
                            (byte[])_dictionaryConverterFloat.Convert(meal.MealItemIDsWithWeight, null, null, "");

                        int success = db.Update(existingMeal);
                    }
                    else
                    {
                        int success = db.Insert(new Meal()
                        {
                            DeliveryNoteId = meal.DeliveryNoteId,
                            Name = meal.Name,
                            DeliveryDate = meal.DeliveryDate,
                            DeliveryTime = meal.DeliveryTime,
                            DeliveryLocation = meal.DeliveryLocation,
                            PickupDate = meal.PickupDate,
                            Contact = meal.Contact,
                            ContactId = meal.ContactId,
                            NumberOfGuests = meal.NumberOfGuests,
                            SilverWare = meal.SilverWare,
                            MealItemIDs = (byte[])_converter.Convert(meal.MealItemIDs, null, null, ""),
                            MealItemIDsWithWeight =(byte[])_dictionaryConverterFloat.Convert(meal.MealItemIDsWithWeight, null, null, "")
                    });
                    }
                    result = "Success";
                }
                catch
                {
                    result = "This meal was not saved.";
                }
            }

            return result;
        }
        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();
        }