Beispiel #1
0
        /// <summary>
        /// 毕业于同一学校
        /// </summary>
        /// <param name="pageIndex">分页页码</param>
        /// <returns></returns>
        public ActionResult _InterestedWithSchools(int pageIndex = 1, string view = null)
        {
            IUser CurrentUser = UserContext.CurrentUser;

            if (CurrentUser == null)
            {
                return(null);
            }

            Dictionary <long, IEnumerable <string> > schoolNameDic = null;

            UserSearcher         searcher = (UserSearcher)SearcherFactory.GetSearcher(UserSearcher.CODE);
            PagingDataSet <User> users    = searcher.SearchInterestedWithSchools(CurrentUser.UserId, pageIndex, pageSize, out schoolNameDic);

            ViewData["schoolNameDic"] = schoolNameDic;

            if (string.IsNullOrEmpty(view))
            {
                return(View(users));
            }
            else
            {
                return(View(view, users));
            }
        }
Beispiel #2
0
        /// <summary>
        /// 供职于同一公司
        /// </summary>
        /// <param name="pageIndex">分页页码</param>
        /// <returns></returns>
        public ActionResult _InterestedWithCompanys(int pageIndex = 1, string view = null)
        {
            IUser CurrentUser = UserContext.CurrentUser;

            if (CurrentUser == null)
            {
                return(null);
            }

            Dictionary <long, IEnumerable <string> > companyNameDic = null;

            UserSearcher         searcher = (UserSearcher)SearcherFactory.GetSearcher(UserSearcher.CODE);
            PagingDataSet <User> users    = searcher.SearchInterestedWithCompanys(CurrentUser.UserId, pageIndex, pageSize, out companyNameDic);

            //设置当前登录用户对当前页用户的关注情况
            Dictionary <long, bool> isCurrentUserFollowDic = new Dictionary <long, bool>();

            foreach (var user in users)
            {
                //如果当前登录用户关注了该用户
                if (followService.IsFollowed(CurrentUser.UserId, user.UserId))
                {
                    isCurrentUserFollowDic.Add(user.UserId, true);
                }
                else
                {
                    isCurrentUserFollowDic.Add(user.UserId, false);
                }
            }
            ViewData["isCurrentUserFollowDic"] = isCurrentUserFollowDic;
            ViewData["companyNameDic"]         = companyNameDic;

            List <User> userList = new List <User>();

            foreach (var user in users)
            {
                if (companyNameDic.ContainsKey(user.UserId) && companyNameDic[user.UserId].Count() > 0)
                {
                    userList.Add(user);
                }
            }
            int pageCount = users.PageCount;

            users = new PagingDataSet <User>(userList);
            ViewData["pageCount"] = pageCount;
            if (string.IsNullOrEmpty(view))
            {
                return(View(users));
            }
            else
            {
                return(View(view, users));
            }
        }
Beispiel #3
0
        /// <summary>
        /// 毕业于同一学校
        /// </summary>
        /// <param name="pageIndex">分页页码</param>
        /// <returns></returns>
        public ActionResult _InterestedWithSchools(int pageIndex = 1, string view = null)
        {
            IUser CurrentUser = UserContext.CurrentUser;

            if (CurrentUser == null)
            {
                return(null);
            }

            Dictionary <long, IEnumerable <string> > schoolNameDic = null;

            UserSearcher         searcher = (UserSearcher)SearcherFactory.GetSearcher(UserSearcher.CODE);
            PagingDataSet <User> users    = searcher.SearchInterestedWithSchools(CurrentUser.UserId, pageIndex, pageSize, out schoolNameDic);

            //设置当前登录用户对当前页用户的关注情况
            Dictionary <long, bool> isCurrentUserFollowDic = new Dictionary <long, bool>();

            foreach (var user in users)
            {
                //如果当前登录用户关注了该用户
                if (followService.IsFollowed(CurrentUser.UserId, user.UserId))
                {
                    isCurrentUserFollowDic.Add(user.UserId, true);
                }
                else
                {
                    isCurrentUserFollowDic.Add(user.UserId, false);
                }
            }
            ViewData["isCurrentUserFollowDic"] = isCurrentUserFollowDic;
            ViewData["schoolNameDic"]          = schoolNameDic;

            if (string.IsNullOrEmpty(view))
            {
                return(View(users));
            }
            else
            {
                return(View(view, users));
            }
        }
Beispiel #4
0
        public ActionResult _InterestedWithAll(int pageSize = 6, int pageIndex = 1, string view = null)
        {
            IUser CurrentUser = UserContext.CurrentUser;

            if (CurrentUser == null)
            {
                return(null);
            }

            //查询同一公司的(优先级最高)
            Dictionary <long, IEnumerable <string> > companyNameDic = null;
            UserSearcher         userSearcher      = (UserSearcher)SearcherFactory.GetSearcher(UserSearcher.CODE);
            PagingDataSet <User> usersWithCompanys = userSearcher.SearchInterestedWithCompanys(CurrentUser.UserId, 1, 30, out companyNameDic);

            //存储感兴趣的人
            List <User> userList = usersWithCompanys.ToList();
            //存储感兴趣的类型
            Dictionary <long, string> interestedDic = usersWithCompanys.ToDictionary(key => key.UserId, value => "WithCompanys");

            //查询有共同关注用户的(优先级第二)
            Dictionary <long, IEnumerable <long> > followedUserIdDic = null;
            Dictionary <long, User> followedUserDic    = null;
            FollowUserSearcher      followUserSearcher = (FollowUserSearcher)SearcherFactory.GetSearcher(FollowUserSearcher.CODE);
            PagingDataSet <User>    usersWithFollows   = followUserSearcher.SearchInterestedWithFollows(CurrentUser.UserId, 1, 30, out followedUserIdDic, out followedUserDic);

            foreach (User user in usersWithFollows)
            {
                if (!interestedDic.ContainsKey(user.UserId))
                {
                    userList.Add(user);
                    interestedDic.Add(user.UserId, "WithFollows");
                }
            }

            //查询同一个学校的(优先级第三)
            Dictionary <long, IEnumerable <string> > schoolNameDic = null;
            PagingDataSet <User> usersWithSchools = userSearcher.SearchInterestedWithSchools(CurrentUser.UserId, 1, 30, out schoolNameDic);

            foreach (User user in usersWithSchools)
            {
                if (!interestedDic.ContainsKey(user.UserId))
                {
                    userList.Add(user);
                    interestedDic.Add(user.UserId, "WithSchools");
                }
            }

            //查询相同标签的(优先级最低)
            Dictionary <long, IEnumerable <string> > tagNameDic = null;
            PagingDataSet <User> usersWithTags = userSearcher.SearchInterestedWithTags(CurrentUser.UserId, 1, 30, out tagNameDic);

            foreach (User user in usersWithTags)
            {
                if (!interestedDic.ContainsKey(user.UserId))
                {
                    userList.Add(user);
                    interestedDic.Add(user.UserId, "WithTags");
                }
            }


            ViewData["followedUserIdDic"] = followedUserIdDic;
            ViewData["followedUserDic"]   = followedUserDic;
            ViewData["companyNameDic"]    = companyNameDic;
            ViewData["schoolNameDic"]     = schoolNameDic;
            ViewData["tagNameDic"]        = tagNameDic;
            ViewData["interestedDic"]     = interestedDic;

            //不指定View,则返回固定的页面,随机显示
            if (string.IsNullOrEmpty(view))
            {
                //随机从用户列表中取pageSize对应的对象组装成新的集合
                List <User> randomUserList = null;
                if (userList.Count <= pageSize)
                {
                    randomUserList = userList;
                }
                else
                {
                    Dictionary <int, User> randomUserDic = new Dictionary <int, User>();
                    Random random = new Random();

                    while (randomUserDic.Count < pageSize)
                    {
                        int index = random.Next(0, userList.Count);
                        if (!randomUserDic.ContainsKey(index))
                        {
                            User user = userList[index];
                            randomUserDic.Add(index, user);
                        }
                    }

                    randomUserList = randomUserDic.OrderBy(n => n.Key).Select(n => n.Value).ToList();
                }

                return(View(randomUserList));
            }
            //指定view,分页显示
            else
            {
                ViewData["pageCount"] = userList.Count / pageSize + 1;
                return(View(view, userList.Skip(pageSize * (pageIndex - 1)).Take(pageSize)));
            }
        }