Esempio n. 1
0
        public async void AddEvent_Click(object sender, RoutedEventArgs e)
        {
            // logika na add úkolu do seznamu

            DateTime MyDate;

            string[]   stringMaleDatum = dtMaly.Text.Split(':');
            HttpClient http            = new HttpClient();

            if (dtVelky.SelectedDate != dtVelky.DisplayDate)
            {
                MyDate = Convert.ToDateTime(dtVelky.SelectedDate);
                MyDate = MyDate.AddHours(Convert.ToDouble(stringMaleDatum[0]));
                MyDate = MyDate.AddMinutes(Convert.ToDouble(stringMaleDatum[1]));
            }
            else
            {
                return;
            }

            Kontrola();
            if (OkDate == true && OkName == true)
            {
                Udalost u = new Udalost(tbNazev.Text, MyDate, tbPoznamka.Text);
                MojeUdalosti.Add(u);
                u.MSGbox();

                try
                {
                    if (chBoxIsPublic.IsChecked == true)
                    {
                        string url = "http://www.g-pos.8u.cz/api/post-event/{\"nazev\":\"" + tbNazev.Text + "\",\"description\":\"" + tbPoznamka.Text + "\",\"od_kdy\":\"" + MyDate.ToString("yyyy-MM-dd") + "\",\"team\":" + user["user"]["team"] + ",\"public\":\"" + 1 + "\",\"user\":\"" + user["user"]["id"] + "\"}";
                        HttpResponseMessage response = await http.GetAsync(url, HttpCompletionOption.ResponseContentRead);

                        string res2 = await response.Content.ReadAsStringAsync();

                        JObject jo2 = JObject.Parse(res2);
                    }
                    else
                    {
                        string url = "http://www.g-pos.8u.cz/api/post-event/{\"nazev\":\"" + tbNazev.Text + "\",\"description\":\"" + tbPoznamka.Text + "\",\"od_kdy\":\"" + MyDate.ToString("yyyy-MM-dd") + "\",\"team\":" + user["user"]["team"] + ",\"public\":\"" + 0 + "\",\"user\":\"" + user["user"]["id"] + "\"}";
                        HttpResponseMessage response = await http.GetAsync(url, HttpCompletionOption.ResponseContentRead);

                        string res2 = await response.Content.ReadAsStringAsync();

                        JObject jo2 = JObject.Parse(res2);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Špatný formát", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }