problem with database
Eduardo Gomez
3,426
Reputation points
Hello
I am using Firebase, to store notes of a notebook
So we have a notebook that has two notes, and then we have a notebook with zero notes
For some reason, I am getting the same two notes on the two notebooks
Here we have my 2 notebooks
and on each notebook, I see the same notes
the Notebook "aaaa" should not have anything
This is where I create the Notebook
CreateNewNotebook = new Command(async () => {
var result = await Application.Current.MainPage.DisplayPromptAsync(string.Empty,
"Notebook name?");
if (!string.IsNullOrEmpty(result)) {
var notebook = new Notebook() {
Name = result,
UserId = App.UserId,
CreatedAt = DateTime.Now.ToString("ddd, MMMM yyyy")
};
await Database.InsertAsync(notebook);
GetNotebooksAsync();
} else {
return;
}
});
SelectedNoteBookCommand = new Command(async () => {
await Application.Current.MainPage.Navigation.PushAsync(new NotesPage());
MessagingCenter.Send(this, "details", SelectedNotebook);
SelectedNotebook = null;
});
GetNotebooksAsync();
}
private async void GetNotebooksAsync() {
var notebooks = await Database.ReadAsync<Notebook>();
if (notebooks != null) {
notebooks.Where(notebook => notebook.Id == App.UserId);
NotebooksCollection.Clear();
foreach (var item in notebooks) {
NotebooksCollection.Add(item);
}
and here is where I get the note and filter it, which is not working
CreateNewNote = new Command(async () => {
var result = await Application.Current.MainPage.DisplayPromptAsync(string.Empty,
"Note name?");
if (!string.IsNullOrEmpty(result)) {
var note = new Note() {
NotebookId = RecivedNotebook.Id,
CreatedAt = DateTime.Now.ToString("ddd, MMMM yyyy"),
UpdatedAt = DateTime.Now.ToString("ddd, MMMM yyyy"),
Title = result
};
await Database.InsertAsync(note);
GetNotes();
} else {
return;
}
});
MessagingCenter.Subscribe<NotebooksVM, Notebook>(this, "details",
(obj, item) => {
RecivedNotebook = item;
});
GetNotes();
}
private async void GetNotes() {
var notes = await Database.ReadAsync<Note>();
if (notes != null) {
notes.Where(n => n.NotebookId == RecivedNotebook.Id);
NotesCollection.Clear();
foreach (var element in notes) {
NotesCollection.Add(element);
}
}
}
}
}