problem with database

Eduardo Gomez 3,426 Reputation points
2021-06-24T22:31:37.907+00:00

Hello

I am using Firebase, to store notes of a notebook

109144-screenshot-2021-06-25-001713.png

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

109029-notebooks.png

and on each notebook, I see the same notes

109191-notes-1.png
109201-notes-2.png

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);  
                }  
            }  
        }  
    }  
}  
  
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,326 questions
{count} votes