コード例 #1
0
ファイル: FriendService.cs プロジェクト: pabalexa/Moments
		public async Task<bool> CreateFriendship (string username)
		{
			using (var handler = new ZumoAuthHeaderHandler ()) 
			{
				using (var client = MobileServiceClientFactory.CreateClient (handler)) 
				{
					var friendUserId = await GetUserId (username);
					var userExists = UserExists (friendUserId);
					if (!userExists) {
						return false;
					}

					var alreadyFriends = await UserIsAlreadyFriend (friendUserId);
					if (alreadyFriends) {
						return false;
					}

					var friendship = new Friendship {
						UserId = AccountService.Instance.User.Id,
						FriendId = friendUserId,
						Accepted = false
					};

					await client.GetTable<Friendship> ().InsertAsync (friendship);

					return true;
				}
			}
		}
コード例 #2
0
        private async Task SendImageToUsers(string imageUrl, List <User> recipients, int displayTime)
        {
            using (var handler = new ZumoAuthHeaderHandler()) {
                using (var client = MobileServiceClientFactory.CreateClient(handler)) {
                    var senderUserId       = AccountService.Instance.User.Id;
                    var senderProfileImage = AccountService.Instance.User.ProfileImage;
                    var senderName         = AccountService.Instance.User.Name;
                    var timeSent           = DateTime.UtcNow;

                    foreach (var user in recipients)
                    {
                        var recipientUserId = user.Id;

                        var moment = new Moment {
                            MomentUrl          = imageUrl,
                            SenderUserId       = senderUserId,
                            SenderName         = senderName,
                            SenderProfileImage = senderProfileImage,
                            RecipientUserId    = recipientUserId,
                            DisplayTime        = displayTime,
                            TimeSent           = timeSent
                        };

                        //Xamarin.Insights.Track ("MomentShared");

                        await client.GetTable <Moment> ().InsertAsync(moment);
                    }
                }
            }
        }
コード例 #3
0
ファイル: FriendService.cs プロジェクト: jgrcoder/Moments
        public async Task <bool> AcceptFriendship(User friend)
        {
            PendingFriends.Remove(friend);
            Friends.Add(friend);

            using (var handler = new ZumoAuthHeaderHandler()) {
                using (var client = MobileServiceClientFactory.CreateClient(handler)) {
                    var existingFriendshipList = await client.GetTable <Friendship> ()
                                                 .Where(friendship => friendship.UserId == friend.Id)
                                                 .Where(friendship => friendship.FriendId == AccountService.Instance.Account.UserId).Select(user => user.Id).ToListAsync();

                    if (existingFriendshipList.Count == 0)
                    {
                        return(false);
                    }
                    else
                    {
                        var friendship = await client.GetTable <Friendship> ().LookupAsync(existingFriendshipList [0]);

                        friendship.Accepted = true;
                        await client.GetTable <Friendship> ().UpdateAsync(friendship);

                        return(true);
                    }
                }
            }
        }
コード例 #4
0
ファイル: FriendService.cs プロジェクト: jgrcoder/Moments
        public async Task <bool> CreateFriendship(string username)
        {
            using (var handler = new ZumoAuthHeaderHandler())
            {
                using (var client = MobileServiceClientFactory.CreateClient(handler))
                {
                    var friendUserId = await GetUserId(username);

                    var userExists = UserExists(friendUserId);
                    if (!userExists)
                    {
                        return(false);
                    }

                    var alreadyFriends = await UserIsAlreadyFriend(friendUserId);

                    if (alreadyFriends)
                    {
                        return(false);
                    }

                    var friendship = new Friendship {
                        UserId   = AccountService.Instance.User.Id,
                        FriendId = friendUserId,
                        Accepted = false
                    };

                    await client.GetTable <Friendship> ().InsertAsync(friendship);

                    return(true);
                }
            }
        }
コード例 #5
0
ファイル: AccountService.cs プロジェクト: jgrcoder/Moments
 private async Task <User> GetCurrentUser()
 {
     using (var handler = new ZumoAuthHeaderHandler()) {
         using (var client = MobileServiceClientFactory.CreateClient(handler)) {
             return(await client.GetTable <User> ().LookupAsync(Account.UserId));
         }
     }
 }
コード例 #6
0
 public async Task DestroyMoment(Moment moment)
 {
     using (var handler = new ZumoAuthHeaderHandler())
     {
         using (var client = MobileServiceClientFactory.CreateClient(handler))
         {
             await client.GetTable <Moment> ().DeleteAsync(moment);
         }
     }
 }
コード例 #7
0
ファイル: MomentService.cs プロジェクト: pabalexa/Moments
		public async Task DestroyMoment (Moment moment)
		{
			using (var handler = new ZumoAuthHeaderHandler ()) 
			{
				using (var client = MobileServiceClientFactory.CreateClient (handler)) 
				{
					await client.GetTable<Moment> ().DeleteAsync (moment);
				}
			}
		}
コード例 #8
0
ファイル: MomentService.cs プロジェクト: pabalexa/Moments
		public async Task<List<Moment>> GetMoments ()
		{
			using (var handler = new ZumoAuthHeaderHandler ()) {
				using (var client = MobileServiceClientFactory.CreateClient (handler)) {
					var friendships = client.GetTable <Moment> ();
					var moments = await friendships.CreateQuery ().Where (moment => moment.RecipientUserId == AccountService.Instance.Account.UserId).Select (moment => moment).ToListAsync ();

					return moments.OrderByDescending (moment => moment.TimeSent).ToList ();
				}
			}
		}
コード例 #9
0
        public async Task <List <Moment> > GetMoments()
        {
            using (var handler = new ZumoAuthHeaderHandler()) {
                using (var client = MobileServiceClientFactory.CreateClient(handler)) {
                    var friendships = client.GetTable <Moment> ();
                    var moments     = await friendships.CreateQuery().Where(moment => moment.RecipientUserId == AccountService.Instance.Account.UserId).Select(moment => moment).ToListAsync();

                    return(moments.OrderByDescending(moment => moment.TimeSent).ToList());
                }
            }
        }
コード例 #10
0
ファイル: AccountService.cs プロジェクト: jgrcoder/Moments
        private async Task <Account> GetCurrentAccount(Account account)
        {
            using (var handler = new ZumoAuthHeaderHandler()) {
                using (var client = MobileServiceClientFactory.CreateClient(handler)) {
                    var currentAccount = await client.GetTable <Account> ()
                                         .Where(acct => acct.Username == account.Username)
                                         .Select(acct => acct).ToListAsync();

                    return(currentAccount [0]);
                }
            }
        }
コード例 #11
0
        private static async Task <string> FetchSas()
        {
            using (var handler = new ZumoAuthHeaderHandler())
            {
                using (var client = MobileServiceClientFactory.CreateClient(handler))
                {
                    var dictionary = new Dictionary <string, string> ();
                    dictionary.Add("containerName", Keys.ContainerName);

                    return(await client.InvokeApiAsync <string> ("sas", System.Net.Http.HttpMethod.Get, dictionary));
                }
            }
        }
コード例 #12
0
ファイル: FriendService.cs プロジェクト: jgrcoder/Moments
        public async Task DenyFriendship(User friend)
        {
            PendingFriends.Remove(friend);

            using (var handler = new ZumoAuthHeaderHandler()) {
                using (var client = MobileServiceClientFactory.CreateClient(handler)) {
                    var existingFriendshipList = await client.GetTable <Friendship> ()
                                                 .Where(friendship => friendship.UserId == friend.Id)
                                                 .Where(friendship => friendship.FriendId == AccountService.Instance.Account.UserId).ToListAsync();

                    var existingFriendship = existingFriendshipList [0];
                    await client.GetTable <Friendship> ().DeleteAsync(existingFriendship);
                }
            }
        }
コード例 #13
0
ファイル: FriendService.cs プロジェクト: pabalexa/Moments
		public async Task RefreshPendingFriendsList ()
		{
			using (var handler = new ZumoAuthHeaderHandler ()) 
			{
				using (var client = MobileServiceClientFactory.CreateClient (handler)) 
				{
					var dictionary = new Dictionary<string, string> ();
					dictionary.Add ("getFriends", "false");
					dictionary.Add ("userId", AccountService.Instance.Account.UserId);

					PendingFriends.Clear ();
					var friends =  await client.InvokeApiAsync<List<User>> ("friends", System.Net.Http.HttpMethod.Get, dictionary);

					var sortedFriends = friends.OrderBy (user => user.Name).ToList ();
					sortedFriends.ForEach (user => PendingFriends.Add (user));
				}
			}
		}
コード例 #14
0
ファイル: FriendService.cs プロジェクト: jgrcoder/Moments
        private async Task <string> GetUserId(string username)
        {
            using (var handler = new ZumoAuthHeaderHandler()) {
                using (var client = MobileServiceClientFactory.CreateClient(handler)) {
                    var userId = await client.GetTable <Account> ().Where(account => account.Username == username)
                                 .Select(account => account.UserId).ToListAsync();

                    if (userId.Count != 0)
                    {
                        return(userId [0]);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
        }
コード例 #15
0
ファイル: FriendService.cs プロジェクト: jgrcoder/Moments
        public async Task RefreshPendingFriendsList()
        {
            using (var handler = new ZumoAuthHeaderHandler())
            {
                using (var client = MobileServiceClientFactory.CreateClient(handler))
                {
                    var dictionary = new Dictionary <string, string> ();
                    dictionary.Add("getFriends", "false");
                    dictionary.Add("userId", AccountService.Instance.Account.UserId);

                    PendingFriends.Clear();
                    var friends = await client.InvokeApiAsync <List <User> > ("friends", System.Net.Http.HttpMethod.Get, dictionary);

                    var sortedFriends = friends.OrderBy(user => user.Name).ToList();
                    sortedFriends.ForEach(user => PendingFriends.Add(user));
                }
            }
        }
コード例 #16
0
ファイル: FriendService.cs プロジェクト: jgrcoder/Moments
        public async Task <bool> UserIsAlreadyFriend(string friendUserId)
        {
            using (var handler = new ZumoAuthHeaderHandler()) {
                using (var client = MobileServiceClientFactory.CreateClient(handler)) {
                    var friendships = client.GetTable <Friendship> ();
                    var friend      = await friendships.CreateQuery().Where(friendship => friendship.UserId == AccountService.Instance.Account.UserId)
                                      .Where(friendship => friendship.FriendId == friendUserId).ToListAsync();

                    if (friend.Count == 0)
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
        }
コード例 #17
0
ファイル: AccountService.cs プロジェクト: pabalexa/Moments
		private async Task<Account> GetCurrentAccount (Account account)
		{
			using (var handler = new ZumoAuthHeaderHandler ()) {
				using (var client = MobileServiceClientFactory.CreateClient (handler)) {
					var currentAccount = await client.GetTable <Account> ()
						.Where (acct => acct.Username == account.Username)
						.Select (acct => acct).ToListAsync ();

					return currentAccount [0];
				}
			}
		}
コード例 #18
0
ファイル: FriendService.cs プロジェクト: pabalexa/Moments
		public async Task<bool> UserIsAlreadyFriend (string friendUserId)
		{
			using (var handler = new ZumoAuthHeaderHandler ()) {
				using (var client = MobileServiceClientFactory.CreateClient (handler)) {
					var friendships = client.GetTable <Friendship> ();
					var friend = await friendships.CreateQuery ().Where (friendship => friendship.UserId == AccountService.Instance.Account.UserId)
						.Where (friendship => friendship.FriendId == friendUserId).ToListAsync ();

					if (friend.Count == 0) {
						return false;
					} else {
						return true;
					}
				}
			}
		}
コード例 #19
0
ファイル: FriendService.cs プロジェクト: pabalexa/Moments
		private async Task<string> GetUserId (string username)
		{
			using (var handler = new ZumoAuthHeaderHandler ()) {
				using (var client = MobileServiceClientFactory.CreateClient (handler)) {
					var userId = await client.GetTable <Account> ().Where (account => account.Username == username)
						.Select (account => account.UserId).ToListAsync ();

					if (userId.Count != 0) {
						return userId [0];
					} else {
						return null;
					}
				}
			}
		}
コード例 #20
0
ファイル: FriendService.cs プロジェクト: pabalexa/Moments
		public async Task DenyFriendship (User friend)
		{
			PendingFriends.Remove (friend);

			using (var handler = new ZumoAuthHeaderHandler ()) {
				using (var client = MobileServiceClientFactory.CreateClient (handler)) {
					var existingFriendshipList = await client.GetTable<Friendship> ()
						.Where (friendship => friendship.UserId == friend.Id)
						.Where (friendship => friendship.FriendId == AccountService.Instance.Account.UserId).ToListAsync ();

					var existingFriendship = existingFriendshipList [0];
					await client.GetTable<Friendship> ().DeleteAsync (existingFriendship);
				}
			}
		}
コード例 #21
0
ファイル: FriendService.cs プロジェクト: pabalexa/Moments
		public async Task<bool> AcceptFriendship (User friend)
		{
			PendingFriends.Remove (friend);
			Friends.Add (friend);

			using (var handler = new ZumoAuthHeaderHandler ()) {
				using (var client = MobileServiceClientFactory.CreateClient (handler)) {
					var existingFriendshipList = await client.GetTable<Friendship> ()
						.Where (friendship => friendship.UserId == friend.Id)
						.Where (friendship => friendship.FriendId == AccountService.Instance.Account.UserId).Select (user => user.Id).ToListAsync ();

					if (existingFriendshipList.Count == 0) {
						return false;
					} else {
						var friendship = await client.GetTable<Friendship> ().LookupAsync (existingFriendshipList [0]);
						friendship.Accepted = true;
						await client.GetTable<Friendship> ().UpdateAsync (friendship);

						return true;
					}
				}
			}
		}
コード例 #22
0
ファイル: MomentService.cs プロジェクト: pabalexa/Moments
		private async Task SendImageToUsers (string imageUrl, List<User> recipients, int displayTime)
		{
			using (var handler = new ZumoAuthHeaderHandler ()) {
				using (var client = MobileServiceClientFactory.CreateClient (handler)) {
					var senderUserId = AccountService.Instance.User.Id;
					var senderProfileImage = AccountService.Instance.User.ProfileImage;
					var senderName = AccountService.Instance.User.Name;
					var timeSent = DateTime.UtcNow;

					foreach (var user in recipients) {
						var recipientUserId = user.Id;

						var moment = new Moment {
							MomentUrl = imageUrl,
							SenderUserId = senderUserId,
							SenderName = senderName,
							SenderProfileImage = senderProfileImage,
							RecipientUserId = recipientUserId,
							DisplayTime = displayTime,
							TimeSent = timeSent
						};

						Xamarin.Insights.Track ("MomentShared");

						await client.GetTable<Moment> ().InsertAsync (moment);
					}
				}
			}
		}
コード例 #23
0
ファイル: MomentService.cs プロジェクト: pabalexa/Moments
		private static async Task<string> FetchSas ()
		{
			using (var handler = new ZumoAuthHeaderHandler ()) 
			{
				using (var client = MobileServiceClientFactory.CreateClient (handler)) 
				{
					var dictionary = new Dictionary<string, string> ();
					dictionary.Add ("containerName", Keys.ContainerName);

					return await client.InvokeApiAsync<string> ("sas", System.Net.Http.HttpMethod.Get, dictionary);
				}
			}
		}
コード例 #24
0
ファイル: AccountService.cs プロジェクト: pabalexa/Moments
		private async Task<User> GetCurrentUser ()
		{
			using (var handler = new ZumoAuthHeaderHandler ()) {
				using (var client = MobileServiceClientFactory.CreateClient (handler)) {
					return await client.GetTable <User> ().LookupAsync (Account.UserId);
				}
			}
		}