Ejemplo n.º 1
0
        async public Task <string> Addfriend(Model.FriendAccount user)
        {
            Model.FriendAccount d1 = await _database.Table <Model.FriendAccount>().Where(x => x.Username == user.Username).FirstOrDefaultAsync();

            if (d1 == null)
            {
                await _database.InsertAsync(user);

                return("Successfully Added");
            }
            else
            {
                return("The username already exist");
            }
        }
Ejemplo n.º 2
0
        async void RemoveFriend(object sender, System.EventArgs e)
        {
            if (!string.IsNullOrEmpty(friendid))
            {
                Console.WriteLine("test 1 " + friendid);
                string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Chattydata.db3");
                SQLiteAsyncConnection _database = new SQLiteAsyncConnection(path);
                Model.FriendAccount   d1        = await _database.Table <Model.FriendAccount>().Where(x => x.ID == friendid).FirstOrDefaultAsync();

                await App.MyDatabase.RemoveFriendInfo(d1);
                await DisplayAlert("Successful", "Remove friend successfully", "OK");

                await Navigation.PushAsync(new FriendListPage(users));
            }
            else
            {
                Console.WriteLine("testing" + friendid);
                await DisplayAlert("Friend list", "No specific friend is found", "OK");
            }
        }
        async void AddFriend(object sender, System.EventArgs e)
        {
            if (!string.IsNullOrEmpty(friendid))
            {
                Console.WriteLine("testing 0 " + friendid);
                string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Chattydata.db3");
                SQLiteAsyncConnection _database = new SQLiteAsyncConnection(path);
                Model.UserAccount     d1        = await _database.Table <Model.UserAccount>().Where(x => x.ID == friendid).FirstOrDefaultAsync();

                Model.FriendAccount d2 = await _database.Table <Model.FriendAccount>().Where(x => (x.Username == users.Username && x.FriendUsername == d1.Username) || (x.Username == d1.Username && x.FriendUsername == users.Username)).FirstOrDefaultAsync();

                Model.FriendID d3 = await _database.Table <Model.FriendID>().Where(x => x.ID == "1").FirstOrDefaultAsync();

                if (d2 == null)
                {
                    List <Model.FriendAccount> usercnt = await _database.Table <Model.FriendAccount>().ToListAsync();

                    int id = Convert.ToInt32(d3.FriendlistID);
                    id                    = id + 1;
                    friend.ID             = id.ToString();
                    friend.Username       = users.Username;
                    friend.FriendUsername = d1.Username;
                    d3.FriendlistID       = id.ToString();
                    await App.MyDatabase.SaveFriendIDInfo(d3);

                    await App.MyDatabase.SaveFriendInfo(friend);
                    await DisplayAlert("Successful", "Add friend successfully", "OK");
                }
                else
                {
                    await DisplayAlert("Fail", "he/she is your friend", "OK");
                }
            }
            else
            {
                await DisplayAlert("Add Friend", "Please select a friend", "OK");
            }
        }
Ejemplo n.º 4
0
 public async Task RemoveFriendInfo(Model.FriendAccount info)
 {
     await _database.DeleteAsync(info);
 }
Ejemplo n.º 5
0
 public async Task SaveFriendInfo(Model.FriendAccount info)
 {
     await _database.InsertAsync(info);
 }