因此,我在应用程序启动上创建了一个异步连接,该连接在“data/user/0/com.your.mypackage/files”中创建了“Profiles.db3”(我检查了一下,它存在并且为空)
每次我尝试注册为新用户时,它总是告诉我有一个现有用户
这是检查现有用户的方法:
public async Task<bool> CheckExistingUser(Profile profile)
{
await Init();
var d1 = db.Table<Profile>().Where(x => x.Username == profile.Username || x.Email == profile.Email).FirstOrDefaultAsync();
if (d1 != null)
{
return true;
}
else
{
return false;
}
}
我在创建新配置文件时使用它:
public async Task<bool> NewProfile(User profile, string picture = "user.png")
{
await Init();
if ((await CheckExistingUser(profile)))
{
return false;
}
else
{
Profile _profile = new Profile
{
Username = profile.Username,
Email = profile.Email,
Password = profile.Password,
Picture = picture,
ProfileType = ProfileType.User,
AdditionalData = JsonConvert.SerializeObject(new
{
profile.BorrowedBooks,
profile.Wishlist,
profile.ReturnedBooks
})
};
await db.InsertAsync(_profile);
return true;
}
}
由于CheckExistingUser返回true,因此此方法始终返回false。
这是为了启动连接
public async Task Init()
{
if (db != null)
return;
db = DependencyService.Get<ISQLiteInterface>().GetSQLiteAsyncConnection();
await db.CreateTableAsync<Profile>();
}
我在SignUp视图模型中称之为:
if (await _profileService.NewProfile((User)Profile))
{
App.Current.MainPage = new AppShell();
}
我对这一切都是新手,所以我不知道问题出在哪里,因为逻辑对我来说似乎是正确的。