Example #1
0
        public ActionResult ViewFriendRequest()
        {
            var friendIdList = new List <string>();
            var userIds      = User.Identity.GetUserId();
            var friendIdQry  = db.Friends.Where(d => d.FriendId == userIds && d.Status == "Pending").Select(d => d.UserId);

            friendIdList.AddRange(friendIdQry);

            List <SearchFriend> friendList = new List <SearchFriend>();

            var userList = (from u in db.Users
                            join pf in db.ProfilePhotoes
                            on u.Id equals pf.UserId into uGroup
                            from pf in uGroup.DefaultIfEmpty()
                            select new
            {
                u.Id,
                u.Name,
                pf.ProfileImage
            }).ToList();

            foreach (string fr in friendIdList)
            {
                var user = userList.Where(s => s.Id.Contains(fr)).ToList();

                foreach (var v in user)
                {
                    SearchFriend sf = new SearchFriend();
                    sf.UserId       = v.Id;
                    sf.UserName     = v.Name;
                    sf.ProfilePhoto = v.ProfileImage;
                    friendList.Add(sf);
                }
            }
            dynamic mymodel = new ExpandoObject();

            mymodel.friendList = friendList.Distinct();

            //Friend Request Count
            var friendIdLists = new List <string>();
            var userIdss      = User.Identity.GetUserId();
            var friendIdQrys  = db.Friends.Where(d => d.FriendId == userIdss && d.Status == "Pending").Select(d => d.UserId);

            friendIdLists.AddRange(friendIdQrys);

            //Notification Count
            string userIdNot     = User.Identity.GetUserId();
            var    notifications = db.ContentNotifications.Where(d => d.FriendId == userIdNot).ToList();

            ViewBag.NotificationCount = notifications.Count();

            var requestCount = friendIdLists.Count();

            ViewBag.RequestCount = requestCount;

            return(View(mymodel));
        }
Example #2
0
        public void ReceiveMessage(IAsyncResult async_result)
        {
            try
            {
                var socket_con_get = async_result.AsyncState as Socket;


                var i_data_length = socket_con_get.EndReceive(async_result);
                var string_data   = Encoding.UTF8.GetString(b_data_buffer, 0, i_data_length);

                // #####################################################
                // 线程通信 消息分发
                ChatReceiveFilter receive_filter = new ChatReceiveFilter();
                int             rest             = 0;
                ChatRequestInfo request_info     = receive_filter.Filter(b_data_buffer, 0, i_data_length, false, out rest);

                ICommand command = null;
                if (request_info != null)
                {
                    switch (request_info.Key)
                    {
                    case "Login": command = new Login(); break;

                    case "FriendList": command = new FriendList(); break;

                    case "ReceiveMsg": command = new ReceiveMsg(); break;

                    case "UpdatePw": command = new UpdatePw(); break;

                    case "SearchFriend": command = new SearchFriend(); break;
                    }
                }

                if (command != null)
                {
                    command.ExecuteCommand(request_info.Body);
                }
                // #####################################################

                socket_connect.BeginReceive(b_data_buffer,
                                            START_POS,
                                            b_data_buffer.Length,
                                            SocketFlags.None,
                                            new AsyncCallback(ReceiveMessage),
                                            socket_connect);
            }
            catch (Exception ex)
            {
                // 异常处理
            }
        }
Example #3
0
        public ActionResult SearchFreind(string searchFriend)
        {
            var users = (from u in db.Users
                         join p in db.ProfilePhotoes
                         on u.Id equals p.UserId into uGroup
                         from p in uGroup.DefaultIfEmpty()
                         select new
            {
                u.Id,
                u.Name,
                p.ProfileImage
            }).ToList();

            if (!String.IsNullOrWhiteSpace(searchFriend))
            {
                users = users.Where(n => n.Name.ToLower().Contains(searchFriend)).ToList();
            }

            List <SearchFriend> friendList = new List <SearchFriend>();

            foreach (var v in users)
            {
                SearchFriend sf = new SearchFriend();
                sf.UserId       = v.Id;
                sf.UserName     = v.Name;
                sf.ProfilePhoto = v.ProfileImage;
                friendList.Add(sf);
            }

            var addedfriendList   = new List <SearchFriend>();
            var pendingFriendList = new List <SearchFriend>();
            var allUser           = new List <SearchFriend>();

            string userId = User.Identity.GetUserId();

            // Friend Added
            var friendIdLst = new List <string>();
            var friendIdQry = db.Friends.Where(d => d.UserId == userId && d.Status == "True").Select(d => d.FriendId);

            friendIdLst.AddRange(friendIdQry);

            var friendIdLst2 = new List <string>();
            var friendIdQry2 = db.Friends.Where(d => d.FriendId == userId && d.Status == "True").Select(d => d.UserId);

            friendIdLst2.AddRange(friendIdQry2);

            var totalFriendList = new List <string>();

            foreach (var VARIABLE in friendIdLst)
            {
                totalFriendList.Add(VARIABLE);
            }

            foreach (var VARIABLE in friendIdLst2)
            {
                totalFriendList.Add(VARIABLE);
            }
            // End

            // Pending Friend
            var pendingFriendIdLst = new List <string>();
            var pendingFriendIdQry = db.Friends.Where(d => d.UserId == userId && d.Status == "Pending").Select(d => d.FriendId);

            pendingFriendIdLst.AddRange(pendingFriendIdQry);

            var pendingFriendIdLst2 = new List <string>();
            var pendingFriendIdQry2 = db.Friends.Where(d => d.FriendId == userId && d.Status == "Pending").Select(d => d.UserId);

            pendingFriendIdLst2.AddRange(pendingFriendIdQry2);

            var totalPendingFriendList = new List <string>();

            foreach (var VARIABLE in pendingFriendIdLst)
            {
                totalPendingFriendList.Add(VARIABLE);
            }

            foreach (var VARIABLE in pendingFriendIdLst2)
            {
                totalPendingFriendList.Add(VARIABLE);
            }
            // End

            foreach (var v in friendList)
            {
                bool exist = false;
                foreach (var item in totalFriendList)
                {
                    if (v.UserId == item)
                    {
                        addedfriendList.Add(v);
                        exist = true;
                    }
                }

                foreach (var item in totalPendingFriendList)
                {
                    if (v.UserId == item)
                    {
                        pendingFriendList.Add(v);
                        exist = true;
                    }
                }

                if (exist == false)
                {
                    allUser.Add(v);
                }
            }

            dynamic mymodel = new ExpandoObject();

            mymodel.AddedfriendList   = addedfriendList;
            mymodel.PendingFriendList = pendingFriendList;
            mymodel.AllUser           = allUser;

            //Friend Request Count
            var friendIdList = new List <string>();
            var userIdss     = User.Identity.GetUserId();
            var friendIdQrys = db.Friends.Where(d => d.FriendId == userIdss && d.Status == "Pending").Select(d => d.UserId);

            friendIdList.AddRange(friendIdQrys);

            //Notification Count
            string userIdNot     = User.Identity.GetUserId();
            var    notifications = db.ContentNotifications.Where(d => d.FriendId == userIdNot).ToList();

            ViewBag.NotificationCount = notifications.Count();

            var requestCount = friendIdList.Count();

            ViewBag.RequestCount = requestCount;

            return(View(mymodel));
        }
Example #4
0
        public ActionResult BrowseLikers(int?id)
        {
            // Find UserIds for likers by postId
            var likers =
                (from like in db.Likes
                 where like.PostId == id
                 select new { like.UserId }).ToList();

            // Find Users for likers
            var users = (from u in db.Users
                         join p in db.ProfilePhotoes
                         on u.Id equals p.UserId into uGroup
                         from p in uGroup.DefaultIfEmpty()
                         select new
            {
                u.Id,
                u.Name,
                p.ProfileImage
            }).ToList();

            //Create List for Post Likers

            List <SearchFriend> LikeUserList = new List <SearchFriend>();

            // For each likers
            foreach (var item1 in likers)
            {
                // Relative information
                foreach (var item2 in users)
                {
                    if (item1.UserId == item2.Id)
                    {
                        SearchFriend sf = new SearchFriend();
                        sf.UserId       = item2.Id;
                        sf.UserName     = item2.Name;
                        sf.ProfilePhoto = item2.ProfileImage;
                        LikeUserList.Add(sf);
                    }
                }
            }

            // Pass to myModel in Profile Controller for view
            dynamic mymodel = new ExpandoObject();

            mymodel.LikeUsers = LikeUserList;

            //Friend Request Count
            var friendIdList = new List <string>();
            var userIdss     = User.Identity.GetUserId();
            var friendIdQrys = db.Friends.Where(d => d.FriendId == userIdss && d.Status == "Pending").Select(d => d.UserId);

            friendIdList.AddRange(friendIdQrys);

            //Notification Count
            string userIdNot     = User.Identity.GetUserId();
            var    notifications = db.ContentNotifications.Where(d => d.FriendId == userIdNot).ToList();

            ViewBag.NotificationCount = notifications.Count();

            var requestCount = friendIdList.Count();

            ViewBag.RequestCount = requestCount;

            return(View(mymodel));
        }
Example #5
0
        public async Task <ActionResult <IEnumerable <ApplicationUser> > > GetUsersSearhced(SearchFriend friendSearched)
        {
            List <ApplicationUser> result = new List <ApplicationUser>();
            //            result = _userManager.GetRolesAsync
            //_userManager.GetUsersInRoleAsync

            var res = await _userManager.GetUsersInRoleAsync("RegisteredUser");

            result = res.ToList();

            if (!String.IsNullOrEmpty(friendSearched.FirstName) && !String.IsNullOrEmpty(friendSearched.LastName))
            {
                return(result.Where(x => x.LastName.ToLower() == friendSearched.LastName.ToLower() && x.FirstName.ToLower() == friendSearched.FirstName.ToLower()).ToList());
            }
            else if (!String.IsNullOrEmpty(friendSearched.FirstName) && String.IsNullOrEmpty(friendSearched.LastName))
            {
                return(result.Where(x => x.FirstName.ToLower() == friendSearched.FirstName.ToLower()).ToList());
            }
            else if (!String.IsNullOrEmpty(friendSearched.LastName) && String.IsNullOrEmpty(friendSearched.FirstName))
            {
                return(result.Where(x => x.LastName.ToLower() == friendSearched.LastName.ToLower()).ToList());
            }
            else
            {
                return(new List <ApplicationUser>());
            }
        }
Example #6
0
        private void btnSearchFriend_Click(object sender, EventArgs e)
        {
            SearchFriend test = new SearchFriend();

            test.Show();
        }
 public async Task <IActionResult> SearchFriend([FromBody] SearchFriend command)
 => Json(await _friendService.SearchFriendsAsync(UserId, command.TextInput));