async private void ReadDataFromWeb() { progressbar.Text = "Fetching new data"; progressbar.ShowAsync(); var client = new HttpClient(); Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; if (!localSettings.Containers.ContainsKey("userInfo")) { MessageDialog msgbox = new MessageDialog("Please log-in first. Go to settings from the main menu."); await msgbox.ShowAsync(); return; } var lastcheck = localSettings.Containers["userInfo"].Values["lastchecklessons"].ToString(); Debug.WriteLine(System.Uri.EscapeUriString(lastcheck)); var response = await client.GetAsync(new Uri("http://codeinn-acecoders.rhcloud.com:8000/query/data?Timestamp=" + System.Uri.EscapeUriString(lastcheck) + "&Table=Lessons")); var result = await response.Content.ReadAsStringAsync(); result = result.Trim(new Char[] { '"' }); Debug.WriteLine(result); DatabaseLesson Db_Helper = new DatabaseLesson(); try { List <Lessons> newless = JsonConvert.DeserializeObject <List <Lessons> >(result); foreach (Lessons less in newless) { try { Db_Helper.InsertLesson(less); } catch { Debug.WriteLine("DB error for item of id: " + less.Id); } } localSettings.Containers["userInfo"].Values["lastchecklessons"] = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ"); progressbar.Text = "New items"; } catch { Debug.WriteLine("No new items"); progressbar.Text = "No New items"; } finally { ReadLessons dblessons = new ReadLessons(); DB_LessonList = dblessons.GetAllLessons(); listBox.ItemsSource = DB_LessonList.OrderByDescending(i => i.Id).ToList(); } progressbar.HideAsync(); }
private async void AddLesson_Click(object sender, RoutedEventArgs e) { DatabaseLesson Db_Helper = new DatabaseLesson(); if (username.Text != "" & email.Text != "") { Db_Helper.InsertLesson(new Lessons(username.Text, email.Text, "Lorem Ipsum")); Frame.Navigate(typeof(LessonViewer)); } else { MessageDialog messageDialog = new MessageDialog("Please fill two fields"); await messageDialog.ShowAsync(); } }