/// <summary> /// Save button functionality. /// Calls methods ValidatePost() and BuildData() /// Asks user confirmation to validate saving or chance to back out. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void SaveNewPost(object sender, RoutedEventArgs e) { if (this.ValidatePost()) { MessageBoxResult wannaInsert = MessageBox.Show("Are you sure you want to add post?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question); if (wannaInsert == MessageBoxResult.Yes) { CollectionHandler collectionHandler = new CollectionHandler(); FirebaseHandler firebaseHandler = new FirebaseHandler(); string[] response = await firebaseHandler.SaveToDb(this.BuildData(), collectionHandler.GetBlogCollection(localesDrobdown.Text)); if (response[0].Equals("200")) { _ = MessageBox.Show("Blog post added", "Info", MessageBoxButton.OK, MessageBoxImage.Information); } else { _ = MessageBox.Show(response[1], "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { _ = MessageBox.Show("Inserting cancelled!", "Info", MessageBoxButton.OK, MessageBoxImage.Information); } } else { _ = MessageBox.Show("Some fields are empty", "Info", MessageBoxButton.OK, MessageBoxImage.Information); } }
/// <summary> /// Saves new news to database /// Controls mouse cursor, sets it to loading and when done to normal. TODO form validation /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void SaveToDb(object sender, RoutedEventArgs e) { Mouse.OverrideCursor = Cursors.Wait; Dictionary <string, object> formData = new Dictionary <string, object> { { "date", dateBox.Text }, { "headline", headlineBox.Text }, { "locale", localeBox.Text }, { "message", messageBox.Text } }; FirebaseHandler FH = new FirebaseHandler(); string[] result = await FH.SaveToDb(formData, this.collectionHandler.GetNewsCollection(formData["locale"].ToString())); Mouse.OverrideCursor = null; if (result[0].Equals("200")) { _ = MessageBox.Show(result[1], "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show(result[1], "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error); } }