Created
November 11, 2020 18:14
-
-
Save rasxod/0de389ceb25f5653f95c684b06f1bfe8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using SQLite; | |
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
namespace sendsms | |
{ | |
[Table("Friends")] | |
public class Friend | |
{ | |
[PrimaryKey, AutoIncrement, Column("_id")] | |
public int Id { get; set; } | |
public string Name { get; set; } | |
public string Email { get; set; } | |
public string Phone { get; set; } | |
} | |
public class FriendAsyncRepository | |
{ | |
SQLiteAsyncConnection database; | |
public FriendAsyncRepository(string databasePath) | |
{ | |
database = new SQLiteAsyncConnection(databasePath); | |
} | |
public async Task CreateTable() | |
{ | |
await database.CreateTableAsync<Friend>(); | |
} | |
public async Task<List<Friend>> GetItemsAsync() | |
{ | |
return await database.Table<Friend>().ToListAsync(); | |
} | |
public async Task<Friend> GetItemAsync(int id) | |
{ | |
return await database.GetAsync<Friend>(id); | |
} | |
public async Task<int> DeleteItemAsync(Friend item) | |
{ | |
return await database.DeleteAsync(item); | |
} | |
public async Task<int> SaveItemAsync(Friend item) | |
{ | |
if (item.Id != 0) | |
{ | |
await database.UpdateAsync(item); | |
return item.Id; | |
} | |
else | |
{ | |
return await database.InsertAsync(item); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment