Hello
I have an issue, and I don't know how to tackle it.
A am using firebase, to save a list of Notebooks and Notes
I am currently displaying the name of each Notebook in a list

but I also want to display in a Label, how many notes I have in every notebook
For example:
I Have a WPF app, that I made, that create notebooks and notes, this get store in firebase
I currently have 2 notebooks
Notebook 1 has Notes 1 and Note 2
Notebook 2 has Note 1
How can I display it in a Label, how many notes the notebook has?
here is my VM
public class NotesVM {
public ObservableCollection<Notebook> NotebooksCollection { get; set; }
public ObservableCollection<Note> NotesCollection { get; set; }
public ICommand CreateNewNotebook { get; set; }
public ICommand SelectedNoteBookCommand { get; set; }
public NotesVM() {
NotebooksCollection = new ObservableCollection<Notebook>();
NotesCollection = new ObservableCollection<Note>();
CreateNewNotebook = new Command(async () => {
Page app = Application.Current.MainPage;
string result = await app.DisplayPromptAsync(string.Empty, "Notebook name?");
Notebook notebook = new Notebook() { Name = result, UserId = App.UserId };
await Database.InsertAsync(notebook);
GetNotebooksAsync();
});
SelectedNoteBookCommand = new Command((parameter) => {
var notebook = parameter as Notebook;
});
GetNotebooksAsync();
}
private async void GetNotebooksAsync() {
var notebooks = await Database.ReadAsync<Notebook>();
if (notebooks != null) {
notebooks.Where(n => n.Id == App.UserId);
NotebooksCollection.Clear();
foreach (var item in notebooks) {
NotebooksCollection.Add(item);
}
}
}
}
and my db
private static readonly string FirebadeDb = "https://safe-wpf-default-rtdb.europe-west1.firebasedatabase.app/";
public static async Task<bool> InsertAsync<T>(T Item) {
string jsonBody = JsonConvert.SerializeObject(Item);
var content = new StringContent(jsonBody, Encoding.UTF8, "application/json");
using (HttpClient client = new HttpClient()) {
var res = await client.PostAsync($"{FirebadeDb}{Item.GetType().Name.ToLower()}.json", content);
if (res.IsSuccessStatusCode) {
return true;
} else {
return false;
}
}
}
public static async Task<List<T>> ReadAsync<T>() where T : HasId {
using (HttpClient client = new HttpClient ()) {
var res = await client.GetAsync($"{FirebadeDb}{typeof(T).Name.ToLower()}.json");
var JsonRes = await res.Content.ReadAsStringAsync();
if (res.IsSuccessStatusCode) {
var valuePairs = JsonConvert.DeserializeObject<Dictionary<string, T>>(JsonRes);
if (valuePairs != null) {
List<T> objts = new List<T>();
foreach (var item in valuePairs) {
item.Value.Id = item.Key;
objts.Add(item.Value);
}
return objts;
}
} else {
return null;
}
return null;
}
}
public static async Task<bool> UpdateAsync<T>(T Item) where T : HasId {
string jsonBody = JsonConvert.SerializeObject(Item);
var content = new StringContent(jsonBody, Encoding.UTF8, "application/json");
using (HttpClient client = new HttpClient()) {
var res = await client.PutAsync($"{FirebadeDb}{Item.GetType().Name.ToLower()}/{Item.Id}.json",
content);
if (res.IsSuccessStatusCode) {
return true;
} else {
return false;
}
}
}
public static async Task<bool> DeleteAsync<T>(T Item) where T : HasId {
using (HttpClient client = new HttpClient()) {
var res = await client.DeleteAsync
($"{FirebadeDb}{Item.GetType().Name.ToLower()}/{Item.Id}.json");
if (res.IsSuccessStatusCode) {
return true;
} else {
return false;
}
}
}
}
}
