Exemplo n.º 1
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var parameter = e.Parameter as Meal;
            // a simple controller that adds a string to a List<string>
            meal = parameter;

            if (meal != null)
            {
                this.txtName.Text = meal.Name;
                this.txtEnergy.Text = meal.Energy.ToString();
                this.txtFat.Text = meal.Fat.ToString();
                this.txtSaturates.Text = meal.Saturates.ToString();
                this.txtSugar.Text = meal.Sugar.ToString();
                this.txtSalt.Text = meal.Salt.ToString();
                this.Kind.SelectedIndex = meal.Kind;


            }
           
        }
Exemplo n.º 2
0
        public static async void updateMeals()
        {
            /*
            private int _mealID;
            private string _name;
            private int _energy;
            private int _fat;
            private int _saturates;
            private int _sugar;
            private int _salt;
            private string _picPath;
            private Boolean _userSet = true;
            0 = Breakfest, 1 = LUNCH, 2 = DINNER, 3 = SNACK 
            private int _kind;

           */
            /*
            example
            {
              "Meals":[
                {
                    "name" : "Toast (json1)",
                    "energy" : 501,
                    "fat" : 10,
                    "saturates" : 3,
                    "sugar" : 2,
                    "salt" : 3,
                    "pic_path" :  "Assets/meals/example.jpeg",
                    "user_set" : false,
                    "kind" : 0
                },
                {
                    "name" : "Pasta (json 2)",
                    "energy" : 501,
                    "fat" : 10,
                    "saturates" : 3,
                    "sugar" : 2,
                    "salt" : 3,
                    "pic_path" :  "Assets/meals/example.jpeg",
                    "user_set" : false,
                    "kind" : 0
                }
              ]
            }

            */

            string stringUri = "http://lelis2008.cloudapp.net/mobileapps/newmeals.json";
            //(future link on azure)
           // stringUri = "http://lelis2008.cloudapp.net/greencampus/www/service.php";
            //stringUri = "http://food2fork.com/api/search?key=323650dff17c671b1896e503d35ebcf2&q=shredded%20chicken";

            var httpClient = new HttpClient();
          //  httpClient.DefaultRequestHeaders.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            // var uri = new Uri("ms-appx:///" + stringUri, UriKind.RelativeOrAbsolute);
            var uri = new Uri(stringUri);
            
            try
            {


                HttpResponseMessage result = await httpClient.GetAsync(uri);

                JsonObject jsonObject = JsonObject.Parse(result.Content.ToString());

               
                foreach (IJsonValue jsonValues in jsonObject.GetNamedArray("Meals", new JsonArray()))
                {
                    try
                    {
                        JsonObject jsonValue = JsonObject.Parse(jsonValues.ToString());
                        Meal meal = new Meal();
                        meal.Name = jsonValue.GetNamedString("name", "");
                        meal.Energy = (int)jsonValue.GetNamedNumber("energy", 0);
                        meal.Fat = (int)jsonValue.GetNamedNumber("fat", 0);
                        meal.Saturates = (int)jsonValue.GetNamedNumber("saturates", 0);
                        meal.Sugar = (int)jsonValue.GetNamedNumber("sugar", 0);
                        meal.Salt = (int)jsonValue.GetNamedNumber("salt", 0);
                        meal.PicPath = jsonValue.GetNamedString("pic_path", "");
                        meal.UserSet = jsonValue.GetNamedBoolean("user_set", false);
                        meal.Kind = (int)jsonObject.GetNamedNumber("kind", 3);

                        new MealDB(meal).save();
                    }
                    catch
                    {
                        continue;
                    }
                }
            }
            catch (Exception ex)
            {
                return;
            }


           


               
        }
Exemplo n.º 3
0
        private void SaveBtn_Click(object sender, RoutedEventArgs e)
        {

            
            if (meal == null)
            {
                meal = new Meal();
            }

            meal.Name = this.txtName.Text;
            meal.Energy = Convert.ToInt32(this.txtEnergy.Text);
            meal.Fat = Convert.ToInt32(this.txtFat.Text);
            meal.Saturates = Convert.ToInt32(this.txtSaturates.Text);
            meal.Sugar = Convert.ToInt32(this.txtSugar.Text);
            meal.Salt = Convert.ToInt32(this.txtSalt.Text);
            meal.Kind = this.Kind.SelectedIndex;
            meal.PicPath = "Assets/meals/example.jpeg";




            MealDB mdb = new MealDB(meal);
            mdb.save();

            Frame.Navigate(typeof(MainPage));
            

        }
Exemplo n.º 4
0
 public MealDB(Meal meal)
 {
     this._meal = meal;
 }