diff --git a/MyFirstMauiApp/LocalDataStorageWithSQLite/MainPage.xaml.cs b/MyFirstMauiApp/LocalDataStorageWithSQLite/MainPage.xaml.cs index 68123a4..36a9a63 100644 --- a/MyFirstMauiApp/LocalDataStorageWithSQLite/MainPage.xaml.cs +++ b/MyFirstMauiApp/LocalDataStorageWithSQLite/MainPage.xaml.cs @@ -26,19 +26,19 @@ namespace LocalDataStorageWithSQLite //int a = 0; } - public void OnNewButtonClicked(object sender, EventArgs args) + public async void OnNewButtonClicked(object sender, EventArgs args) { statusMessage.Text = ""; - App.PersonRepo.AddNewPerson(newPerson.Text); + await App.PersonRepo.AddNewPerson(newPerson.Text); statusMessage.Text = App.PersonRepo.StatusMessage; } - public void OnGetButtonClicked(object sender, EventArgs args) + public async void OnGetButtonClicked(object sender, EventArgs args) { statusMessage.Text = ""; - List people = App.PersonRepo.GetAllPeople(); + List people = await App.PersonRepo.GetAllPeople(); peopleList.ItemsSource = people; } } diff --git a/MyFirstMauiApp/LocalDataStorageWithSQLite/Repositories/PersonRepository.cs b/MyFirstMauiApp/LocalDataStorageWithSQLite/Repositories/PersonRepository.cs index b9841de..0e467fc 100644 --- a/MyFirstMauiApp/LocalDataStorageWithSQLite/Repositories/PersonRepository.cs +++ b/MyFirstMauiApp/LocalDataStorageWithSQLite/Repositories/PersonRepository.cs @@ -16,14 +16,14 @@ namespace LocalDataStorageWithSQLite.Repositories // TODO: Add variable for the SQLite connection - private SQLiteConnection _conn; - private void Init() + private SQLiteAsyncConnection _conn; + private async Task Init() { if (_conn != null) return; - _conn = new SQLiteConnection(_dbPath); - _conn.CreateTable(); + _conn = new SQLiteAsyncConnection(_dbPath); + await _conn.CreateTableAsync(); } public PersonRepository(string dbPath) @@ -31,17 +31,17 @@ namespace LocalDataStorageWithSQLite.Repositories _dbPath = dbPath; } - public void AddNewPerson(string name) + public async Task AddNewPerson(string name) { int result = 0; try { - Init(); + await Init(); if (string.IsNullOrEmpty(name)) throw new Exception("Valid name required"); - result = _conn.Insert(new Person { Name = name }); + result = await _conn.InsertAsync(new Person { Name = name }); StatusMessage = string.Format("{0} record(s) added (Name: {1})", result, name); } @@ -52,12 +52,12 @@ namespace LocalDataStorageWithSQLite.Repositories } - public List GetAllPeople() + public async Task> GetAllPeople() { try { - Init(); - return _conn.Table().ToList(); + await Init(); + return await _conn.Table().ToListAsync(); } catch (Exception ex) {