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?
Android-App/App3/App3/Services/DataService.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
69 lines (54 sloc)
1.5 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; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Runtime.CompilerServices; | |
using System.Text; | |
using System.Threading.Tasks; | |
using App3.Models; | |
using App3.Services; | |
using SQLite; | |
using Xamarin.Essentials; | |
namespace App3.Services | |
{ | |
public class DataService : IDataService | |
{ | |
SQLiteAsyncConnection db; | |
async Task Init() | |
{ | |
if (db != null) | |
return; | |
var databasePath = Path.Combine(FileSystem.AppDataDirectory, "MyData.db"); | |
db = new SQLiteAsyncConnection(databasePath); | |
await db.CreateTableAsync<User>(); | |
} | |
public async Task AddUser(string Username, string Password) | |
{ | |
await Init(); | |
var User = new User | |
{ | |
UserName = Username, | |
Password = Password, | |
}; | |
var id = await db.InsertAsync(User); | |
} | |
public async Task RemoveUser(int id) | |
{ | |
await Init(); | |
await db.DeleteAsync<User>(id); | |
} | |
public async Task<IEnumerable<User>> GetUser() | |
{ | |
await Init(); | |
var User = await db.Table<User>().ToListAsync(); | |
return User; | |
} | |
public Task AddUser(object username, object password) | |
{ | |
throw new NotImplementedException(); | |
} | |
public Task AddUser(string username, object password) | |
{ | |
throw new NotImplementedException(); | |
} | |
} | |
} |