示例#1
0
        // Hälytyksen tilamuutos PUT

        public async void HalytysSwitch_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (HalytysSwitch.IsToggled == false)

            {
                Halytys_Label.Text = halypois;

                //päivitystoiminto API:n kautta tietokantaan

                int     id      = 1;
                int     stat    = 0;
                Halytys halytys = new Halytys()
                {
                    HalytinId     = id,
                    HalytinStatus = stat
                };

                var json    = JsonConvert.SerializeObject(halytys);
                var content = new StringContent(json, Encoding.UTF8, "application/json");

                HttpClient client = new HttpClient();
                var        result = await client.PutAsync
                                        (string.Concat("https://kotiapi.azurewebsites.net/api/halytys/", halytys.HalytinId), content);
            }
            else
            {
                Halytys_Label.Text = halypaalle;

                //päivitystoiminto API:n kautta tietokantaan

                int     id      = 1;
                int     stat    = 1;
                Halytys halytys = new Halytys()
                {
                    HalytinId     = id,
                    HalytinStatus = stat
                };

                var json    = JsonConvert.SerializeObject(halytys);
                var content = new StringContent(json, Encoding.UTF8, "application/json");

                HttpClient client = new HttpClient();
                var        result = await client.PutAsync
                                        (string.Concat("https://kotiapi.azurewebsites.net/api/halytys/", halytys.HalytinId), content);
            }
        }
示例#2
0
        private async void GetHalytyksenTila()
        {
            HttpClient client = new HttpClient();

            string response = await client.GetStringAsync("https://kotiapi.azurewebsites.net/api/halytys/1");

            Halytys halytysItem = JsonConvert.DeserializeObject <Halytys>(response);

            int h = halytysItem.HalytinStatus;

            if (h == 0)
            {
                HalytysSwitch.IsToggled = false;
                Halytys_Label.Text      = halypois;
            }
            else
            {
                HalytysSwitch.IsToggled = true;
                Halytys_Label.Text      = halypaalle;
            };
        }