Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
UEngage/UEngage/Data/UserDatabase.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
47 lines (41 sloc)
1.12 KB
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 System.Collections.Generic; | |
using System.Threading.Tasks; | |
using SQLite; | |
using UEngage.Models; | |
namespace UEngage.Data | |
{ | |
public class UserDatabase | |
{ | |
readonly SQLiteAsyncConnection _database; | |
public UserDatabase(string dbPath) | |
{ | |
_database = new SQLiteAsyncConnection(dbPath); | |
_database.CreateTableAsync<User_>().Wait(); | |
} | |
public Task<List<User_>> GetaUsersAsync() | |
{ | |
return _database.Table<User_>().ToListAsync(); | |
} | |
public Task<User_> GetUserAsync(int id) | |
{ | |
return _database.Table<User_>() | |
.Where(i => i.ID == id) | |
.FirstOrDefaultAsync(); | |
} | |
public Task<int> SaveUserAsync(User_ user) | |
{ | |
if (user.ID != 0) | |
{ | |
return _database.UpdateAsync(user); | |
} | |
else | |
{ | |
return _database.InsertAsync(user); | |
} | |
} | |
public Task<int> DeleteUserAsync(User_ user) | |
{ | |
return _database.DeleteAsync(user); | |
} | |
} | |
} |