예제 #1
0
        private async Task Insert(Account account, bool isLogin)
        {
            using (var handler = new AuthenticationHandler()) {
                using (var client = MobileServiceClientFactory.CreateClient(handler)) {
                    var table      = client.GetTable <Account> ();
                    var parameters = new Dictionary <string, string> {
                        { "login", isLogin.ToString().ToLower() }
                    };

                    await table.InsertAsync(account, parameters);
                }
            }
        }
예제 #2
0
        public async Task <bool> DeleteAccount()
        {
            bool result;

            try {
                using (var handler = new AuthenticationHandler()) {
                    using (var client = MobileServiceClientFactory.CreateClient(handler)) {
                        // Account
                        var accountTable = client.GetTable <Account> ();
                        await accountTable.DeleteAsync(Account);

                        // User
                        var userTable = client.GetTable <User> ();
                        await userTable.DeleteAsync(User);

                        // Friendships
                        var friendships = await client.GetTable <Friendship> ()
                                          .Where(friendship => friendship.UserId == AccountService.Instance.User.Id).Select(friendship => friendship).ToListAsync();

                        friendships.AddRange(await client.GetTable <Friendship> ()
                                             .Where(friendship => friendship.FriendId == AccountService.Instance.User.Id).Select(friendship => friendship).ToListAsync());

                        var friendshipsTable = client.GetTable <Friendship> ();
                        foreach (var friend in friendships)
                        {
                            await friendshipsTable.DeleteAsync(friend);
                        }

                        // Moments
                        var moments = await client.GetTable <Moment> ()
                                      .Where(moment => moment.SenderUserId == AccountService.Instance.User.Id).Select(moment => moment).ToListAsync();

                        moments.AddRange(await client.GetTable <Moment> ()
                                         .Where(moment => moment.RecipientUserId == AccountService.Instance.User.Id).Select(moment => moment).ToListAsync());

                        var momentsTable = client.GetTable <Moment> ();
                        foreach (var moment in moments)
                        {
                            await momentsTable.DeleteAsync(moment);
                        }
                    }
                }

                result = true;
            } catch {
                result = false;
            }

            return(result);
        }
예제 #3
0
		private async Task Insert (Account account, bool isLogin)
		{
			using (var handler = new AuthenticationHandler ()) {

				using (var client = MobileServiceClientFactory.CreateClient (handler)) {
					var table = client.GetTable<Account> ();
					var parameters = new Dictionary<string, string> {
						{ "login", isLogin.ToString ().ToLower ()}
					};

					await table.InsertAsync (account, parameters);
				}
			}
		}
예제 #4
0
		public async Task<bool> DeleteAccount ()
		{
			bool result;

			try {
				using (var handler = new AuthenticationHandler ()) {
					using (var client = MobileServiceClientFactory.CreateClient (handler)) {
						// Account
						var accountTable = client.GetTable<Account> ();
						await accountTable.DeleteAsync (Account);

						// User
						var userTable = client.GetTable <User> ();
						await userTable.DeleteAsync (User);

						// Friendships
						var friendships = await client.GetTable<Friendship> ()
							.Where (friendship => friendship.UserId == AccountService.Instance.User.Id).Select (friendship => friendship).ToListAsync ();

						friendships.AddRange (await client.GetTable<Friendship> ()
							.Where (friendship => friendship.FriendId == AccountService.Instance.User.Id).Select (friendship => friendship).ToListAsync ());

						var friendshipsTable = client.GetTable<Friendship> ();
						foreach (var friend in friendships) {
							await friendshipsTable.DeleteAsync (friend);
						}

						// Moments
						var moments = await client.GetTable<Moment> ()
							.Where (moment => moment.SenderUserId == AccountService.Instance.User.Id).Select (moment => moment).ToListAsync ();

						moments.AddRange (await client.GetTable<Moment> ()
							.Where (moment => moment.RecipientUserId == AccountService.Instance.User.Id).Select (moment => moment).ToListAsync ());

						var momentsTable = client.GetTable<Moment> ();
						foreach (var moment in moments) {
							await momentsTable.DeleteAsync (moment);
						}
					}
				}

				result = true;
			} catch {
				result = false;
			}

			return result;
		}