예제 #1
0
        /// <summary>
        /// 输出多用户选择器
        /// </summary>
        /// <param name="htmlHelper">被扩展的htmlHelper</param>
        /// <param name="name">控件表单名</param>
        /// <param name="selectionLimit">限制选中的用户数</param>
        /// <param name="selectedUserIds">初始选中用户Id集合</param>
        /// <param name="searchScope">搜索范围</param>
        /// <param name="showDropDownMenu">是否显示下拉菜单</param>
        /// <param name="widthType">宽度</param>
        /// <param name="selectionAddedCallBack">添加成功事件回调方法</param>
        /// <remarks>仅限登录用户使用</remarks>
        /// <returns>MvcHtmlString</returns>
        public static MvcHtmlString UserSelector(this HtmlHelper htmlHelper, string name, int selectionLimit, IEnumerable <long> selectedUserIds = null, SelectorWidthType widthType = SelectorWidthType.Long, UserSelectorSearchScope searchScope = UserSelectorSearchScope.FollowedUser, bool showDropDownMenu = true, string selectionAddedCallBack = null)
        {
            if (selectedUserIds == null)
            {
                selectedUserIds = new List <long>();
            }

            IUserService userService = DIContainer.Resolve <IUserService>();

            var selectedUsers = userService.GetFullUsers(selectedUserIds)
                                .Select(n => new
            {
                userId        = n.UserId,
                displayName   = n.DisplayName,
                trueName      = n.TrueName,
                nickName      = n.NickName,
                userAvatarUrl = SiteUrls.Instance().UserAvatarUrl(n, AvatarSizeType.Small)
            });
            string followGroupsJSON = "[]";

            if (showDropDownMenu)
            {
                var followGroups = new CategoryService().GetOwnerCategories(UserContext.CurrentUser.UserId, TenantTypeIds.Instance().User()).Select(n => new
                {
                    name  = n.CategoryName.Length > 15 ? n.CategoryName.Substring(0, 15): n.CategoryName,
                    value = n.CategoryId
                });
                followGroupsJSON = Json.Encode(followGroups);
            }

            string widthClass = "tn-longer";

            switch (widthType)
            {
            case SelectorWidthType.Short:
                widthClass = "tn-short";
                break;

            case SelectorWidthType.Medium:
                widthClass = "tn-medium";
                break;

            case SelectorWidthType.Long:
                widthClass = "tn-long";
                break;

            case SelectorWidthType.Longer:
                widthClass = "tn-longer";
                break;

            case SelectorWidthType.Longest:
                widthClass = "tn-longest";
                break;

            default:
                widthClass = "tn-longer";
                break;
            }

            htmlHelper.ViewData["controlName"]            = name;
            htmlHelper.ViewData["widthClass"]             = widthClass;
            htmlHelper.ViewData["selectionLimit"]         = selectionLimit;
            htmlHelper.ViewData["searchScope"]            = searchScope;
            htmlHelper.ViewData["showDropDownMenu"]       = showDropDownMenu;
            htmlHelper.ViewData["selectionAddedCallBack"] = selectionAddedCallBack;
            return(htmlHelper.EditorForModel("UserSelector", new { selectedUsers = Json.Encode(selectedUsers), followGroups = followGroupsJSON }));
        }
예제 #2
0
        /// <summary>
        /// 输出单用户选择器
        /// </summary>
        /// <param name="htmlHelper">被扩展的htmlHelper</param>
        /// <param name="name">控件表单名</param>
        /// <param name="selectedUserId">初始选中用户Id</param>
        /// <param name="searchScope">搜索范围</param>
        /// <param name="selectionAddedCallBack">添加成功事件回调方法</param>
        /// <remarks>仅限登录用户使用</remarks>
        /// <returns></returns>
        public static MvcHtmlString UserSelector(this HtmlHelper htmlHelper, string name, long?selectedUserId = null, UserSelectorSearchScope searchScope = UserSelectorSearchScope.Site, string selectionAddedCallBack = null)
        {
            IEnumerable <long> selectedUserIds = null;

            if (selectedUserId != null)
            {
                selectedUserIds = new List <long> {
                    selectedUserId.Value
                }
            }
            ;
            return(htmlHelper.UserSelector(name, 1, selectedUserIds, SelectorWidthType.Medium, searchScope, false, selectionAddedCallBack));
        }
예제 #3
0
        public JsonResult SearchUsers(UserSelectorSearchScope searchScope)
        {
            string term = Request.QueryString.GetString("q", string.Empty);
            int topNumber = 8;
            if (string.IsNullOrEmpty(term))
                return Json(new { }, JsonRequestBehavior.AllowGet);
            term = WebUtility.UrlDecode(term);
            term = term.ToLower();
            long userId = 0;
            if (UserContext.CurrentUser != null)
                userId = UserContext.CurrentUser.UserId;
            IEnumerable<User> users = null;
            var followService = new FollowService();

            var followedUsers = followService.GetFollows(userId, null, Follow_SortBy.FollowerCount_Desc);
            if (searchScope == UserSelectorSearchScope.FollowedUser)
            {
                IUserService userService = DIContainer.Resolve<IUserService>();
                users = userService.GetFullUsers(followedUsers.Select(n => n.FollowedUserId))
                       .Where(n => n.TrueName.ToLower().Contains(term)
                                   || n.NickName.ToLower().Contains(term)
                                   || GetNoteName(followedUsers, n.UserId).ToLower().Contains(term)
                                   || n.UserName.ToLower().Contains(term))
                                   .Take(topNumber);
            }
            else
            {

                UserSearcher userSearcher = (UserSearcher)SearcherFactory.GetSearcher(UserSearcher.CODE);
                UserFullTextQuery query = new UserFullTextQuery();
                query.Keyword = term;
                query.PageIndex = 1;
                query.PageSize = topNumber;
                users = userSearcher.Search(query);
            }
            return Json(users
                   .Select(n => new
                   {
                       userId = n.UserId,
                       displayName = n.DisplayName,
                       userName = n.UserName,
                       trueName = n.TrueName,
                       nickName = n.NickName,
                       noteName = GetNoteName(followedUsers, n.UserId),
                       userAvatarUrl = SiteUrls.Instance().UserAvatarUrl(n, AvatarSizeType.Small)
                   }), JsonRequestBehavior.AllowGet);
        }
 /// <summary>
 /// 输出单用户选择器
 /// </summary>
 /// <param name="htmlHelper">被扩展的htmlHelper</param>
 /// <param name="name">控件表单名</param>
 /// <param name="selectedUserId">初始选中用户Id</param>
 /// <param name="searchScope">搜索范围</param>
 /// <param name="selectionAddedCallBack">添加成功事件回调方法</param>
 /// <remarks>仅限登录用户使用</remarks>
 /// <returns></returns>
 public static MvcHtmlString UserSelector(this HtmlHelper htmlHelper, string name, long? selectedUserId = null, UserSelectorSearchScope searchScope = UserSelectorSearchScope.Site, string selectionAddedCallBack = null)
 {
     IEnumerable<long> selectedUserIds = null;
     if (selectedUserId != null)
         selectedUserIds = new List<long> { selectedUserId.Value };
     return htmlHelper.UserSelector(name, 1, selectedUserIds, SelectorWidthType.Medium, searchScope, false, selectionAddedCallBack);
 }
        /// <summary>
        /// 输出多用户选择器
        /// </summary>
        /// <param name="htmlHelper">被扩展的htmlHelper</param>
        /// <param name="name">控件表单名</param>
        /// <param name="selectionLimit">限制选中的用户数</param>
        /// <param name="selectedUserIds">初始选中用户Id集合</param>
        /// <param name="searchScope">搜索范围</param>
        /// <param name="showDropDownMenu">是否显示下拉菜单</param>
        /// <param name="widthType">宽度</param>
        /// <param name="selectionAddedCallBack">添加成功事件回调方法</param>
        /// <remarks>仅限登录用户使用</remarks>
        /// <returns>MvcHtmlString</returns>
        public static MvcHtmlString UserSelector(this HtmlHelper htmlHelper, string name, int selectionLimit, IEnumerable<long> selectedUserIds = null, SelectorWidthType widthType = SelectorWidthType.Long, UserSelectorSearchScope searchScope = UserSelectorSearchScope.FollowedUser, bool showDropDownMenu = true, string selectionAddedCallBack = null)
        {
            if (selectedUserIds == null)
                selectedUserIds = new List<long>();

            IUserService userService = DIContainer.Resolve<IUserService>();

            var selectedUsers = userService.GetFullUsers(selectedUserIds)
             .Select(n => new
            {
                userId = n.UserId,
                displayName = n.DisplayName,
                trueName = n.TrueName,
                nickName = n.NickName,
                userAvatarUrl = SiteUrls.Instance().UserAvatarUrl(n, AvatarSizeType.Small)
            });
            string followGroupsJSON = "[]";
            if (showDropDownMenu)
            {
                var followGroups = new CategoryService().GetOwnerCategories(UserContext.CurrentUser.UserId, TenantTypeIds.Instance().User()).Select(n => new
                {
                    name = n.CategoryName.Length > 15 ? n.CategoryName.Substring(0,15): n.CategoryName,
                    value = n.CategoryId
                });
                followGroupsJSON = Json.Encode(followGroups);
            }

            string widthClass = "tn-longer";
            switch (widthType)
            {
                case SelectorWidthType.Short:
                    widthClass = "tn-short";
                    break;
                case SelectorWidthType.Medium:
                    widthClass = "tn-medium";
                    break;
                case SelectorWidthType.Long:
                    widthClass = "tn-long";
                    break;
                case SelectorWidthType.Longer:
                    widthClass = "tn-longer";
                    break;
                case SelectorWidthType.Longest:
                    widthClass = "tn-longest";
                    break;
                default:
                    widthClass = "tn-longer";
                    break;
            }

            htmlHelper.ViewData["controlName"] = name;
            htmlHelper.ViewData["widthClass"] = widthClass;
            htmlHelper.ViewData["selectionLimit"] = selectionLimit;
            htmlHelper.ViewData["searchScope"] = searchScope;
            htmlHelper.ViewData["showDropDownMenu"] = showDropDownMenu;
            htmlHelper.ViewData["selectionAddedCallBack"] = selectionAddedCallBack;
            return htmlHelper.EditorForModel("UserSelector", new { selectedUsers = Json.Encode(selectedUsers), followGroups = followGroupsJSON });
        }
예제 #6
0
파일: SiteUrls.cs 프로젝트: hbulzy/SYS
 /// <summary>
 /// 搜索用户
 /// </summary>
 /// <returns></returns>
 public string SearchUsers(UserSelectorSearchScope searchScope)
 {
     return CachedUrlHelper.Action("SearchUsers", "Channel", CommonAreaName, new RouteValueDictionary { { "searchScope", searchScope } });
 }