/// <summary> /// Loads news from firestore. /// Controls mouse cursor to show loading. Raises exception if firebase fails. /// </summary> /// <exception cref="Exception">Errors in firebase</exception> private async void GetData() { Mouse.OverrideCursor = Cursors.Wait; try { FirebaseHandler fbh = new FirebaseHandler(); CollectionHandler collectionHandler = new CollectionHandler(); List <Dictionary <string, object> > list1 = await fbh.GetCollection(collectionHandler.GetNewsCollection("fi")); List <Dictionary <string, object> > list2 = await fbh.GetCollection(collectionHandler.GetNewsCollection("en")); this.news.AddRange(list1); this.news.AddRange(list2); Mouse.OverrideCursor = null; this.FillDataCollection(); } catch (Exception e) { _ = MessageBox.Show(e.Message, "There was an error", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Deletes message. Gets id to remove from input field. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void DeleteMessage(object sender, RoutedEventArgs e) { MessageBoxResult result = MessageBox.Show("Are you sure you want to delete?", "Deleting", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes && idToDelete.Text.Length > 0) { FirebaseHandler firebaseHandler = new FirebaseHandler(); CollectionHandler collection = new CollectionHandler(); string locale = ""; int index = 0; foreach (dataModel item in this.dataCollection) { if (item.id.Equals(idToDelete.Text)) { locale = item.locale; index = this.dataCollection.IndexOf(item); } } if (locale.Equals("fi") || locale.Equals("en")) { string[] response = await firebaseHandler.DeleteFromDb(idToDelete.Text, collection.GetNewsCollection(locale)); if (response[0].Equals("200")) { this.dataCollection.RemoveAt(index); _ = MessageBox.Show("Deleted succesfully", "Deleted", MessageBoxButton.OK, MessageBoxImage.Information); } else { _ = MessageBox.Show(response[1], "Error happened", MessageBoxButton.OK, MessageBoxImage.Error); } } else { _ = MessageBox.Show("Error cannot get locale from news delete. Are you sure id is valid?", "Error happened", MessageBoxButton.OK, MessageBoxImage.Error); } } else if (idToDelete.Text.Length == 0) { _ = MessageBox.Show("Id to delete cannot be empty!", "Id is empty", MessageBoxButton.OK, MessageBoxImage.Information); } else { _ = MessageBox.Show("Nothing deleted!", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); } }