Beispiel #1
0
        async void OnAddFoodClicked()
        {
            if (Name == null || Calories == null)
            {
                System.Diagnostics.Debug.WriteLine("name or cal not set");
                await Application.Current.MainPage.DisplayAlert("Missing Field", "Please Enter all Fields", "Ok");
            }
            else
            {
                int cal;
                food.Name = Name;
                try
                {
                    cal           = Convert.ToInt32(Calories);
                    food.Calories = cal;
                    var mongoService = new MongoService();
                    await mongoService.CreateFood(food);

                    await Application.Current.MainPage.Navigation.PopAsync();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
            }
        }