Exemplo n.º 1
0
        /// <summary>
        /// Returns a FriendRequestsViewModel with a list of all accepted friends for the current browsing user
        /// </summary>
        /// <returns></returns>
        public FriendRequestsViewModel acceptedFriendsToViewModel()
        {
            //get the user id who is browsing
            int userId = _myHelper.getBrowsingUserId();

            //get all the friend request which involve him and a status of accepted
            var acceptedFriends = _database.Query<UmbBook.pocos.FriendRequest>("SELECT * FROM FriendRequests WHERE RequestingUserId =@0 AND accepted=@1 OR TargetUserId = @0 AND accepted=@1", userId.ToString(), "true");

            FriendRequestsViewModel acceptedFriendsToViewModel = new FriendRequestsViewModel();

            //let's get the imember objects for each and store it in the
            foreach (var item in acceptedFriends)
            {
                //because we got 2 ids , but are just interested in either one of them (not the user himself
                int userIdToAdd;

                if (item.RequestingUserId == userId)
                {
                    userIdToAdd = item.TargetUserId;
                }
                else
                {
                    userIdToAdd = item.RequestingUserId;
                }
                acceptedFriendsToViewModel.friendRequests.Add(_memberService.GetById(userIdToAdd));
            }
            return acceptedFriendsToViewModel;
        }
Exemplo n.º 2
0
        public FriendRequestsViewModel RenderFriendRequests()
        {
            //get the user id who is browsing
            int userId = _myHelper.getBrowsingUserId();

            //get all the friend request which involve him and a status of not accepted
            var friendRequests = _database.Query<UmbBook.pocos.FriendRequest>("SELECT * FROM FriendRequests WHERE TargetUserId = @0 AND accepted = @1", userId.ToString(), "false");

            FriendRequestsViewModel incomcingFriendRequests = new FriendRequestsViewModel();

            //let's get the imember objects for each and store it in the
            foreach (var item in friendRequests)
            {
                incomcingFriendRequests.friendRequests.Add(_memberService.GetById(item.RequestingUserId));
            }

            return incomcingFriendRequests;
        }