コード例 #1
0
        public IHttpActionResult GetOnlineFriendsCount()
        {
            var userName = JwtManager.GetUserNameFromToken(
                Request.Headers.Authorization.Parameter);
            var user          = UnitOfWork.UserRepository.GetByName(userName);
            int onlineCounter = 0;
            var friends       = UnitOfWork.FriendshipRepository.GetFriends(user.Id);
            var onlineFriends = OnlineWorker.MarkIfOnline(friends);

            onlineFriends.ForEach(f =>
            {
                if (f.Online)
                {
                    onlineCounter++;
                }
            });
            return(Ok(onlineCounter));
        }
コード例 #2
0
        public IHttpActionResult FindUsers(
            [FromUri] UserInfoBindingModel searchUser,
            [FromUri(Name = "p")] int page)
        {
            var allUsers = UnitOfWork.UserRepository.FindUsers(searchUser, UsersPerPage, page);
            //use this method for efficient search and marking online users
            var users     = OnlineWorker.MarkIfOnline(allUsers);
            var pageCount = UnitOfWork.UserRepository.FindUsersPageCount(searchUser, UsersPerPage);
            Pair <UserReturnModel[], int> data = Pair.Make(users, pageCount);

            return(Ok(data));
        }