|
|
@ -16,14 +16,14 @@ namespace LocalDataStorageWithSQLite.Repositories |
|
|
|
|
|
|
|
|
|
|
|
// TODO: Add variable for the SQLite connection |
|
|
|
// TODO: Add variable for the SQLite connection |
|
|
|
|
|
|
|
|
|
|
|
private SQLiteConnection _conn; |
|
|
|
private SQLiteAsyncConnection _conn; |
|
|
|
private void Init() |
|
|
|
private async Task Init() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (_conn != null) |
|
|
|
if (_conn != null) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
_conn = new SQLiteConnection(_dbPath); |
|
|
|
_conn = new SQLiteAsyncConnection(_dbPath); |
|
|
|
_conn.CreateTable<Person>(); |
|
|
|
await _conn.CreateTableAsync<Person>(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public PersonRepository(string dbPath) |
|
|
|
public PersonRepository(string dbPath) |
|
|
@ -31,17 +31,17 @@ namespace LocalDataStorageWithSQLite.Repositories |
|
|
|
_dbPath = dbPath; |
|
|
|
_dbPath = dbPath; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void AddNewPerson(string name) |
|
|
|
public async Task AddNewPerson(string name) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int result = 0; |
|
|
|
int result = 0; |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
Init(); |
|
|
|
await Init(); |
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(name)) |
|
|
|
if (string.IsNullOrEmpty(name)) |
|
|
|
throw new Exception("Valid name required"); |
|
|
|
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); |
|
|
|
StatusMessage = string.Format("{0} record(s) added (Name: {1})", result, name); |
|
|
|
} |
|
|
|
} |
|
|
@ -52,12 +52,12 @@ namespace LocalDataStorageWithSQLite.Repositories |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public List<Person> GetAllPeople() |
|
|
|
public async Task<List<Person>> GetAllPeople() |
|
|
|
{ |
|
|
|
{ |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
Init(); |
|
|
|
await Init(); |
|
|
|
return _conn.Table<Person>().ToList(); |
|
|
|
return await _conn.Table<Person>().ToListAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
{ |
|
|
|