Inheritance: ChiakiYu.Core.Data.PagingDto
Exemple #1
0
        /// <summary>
        ///     获取用户分页数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public PagingList<UserDto> GetUsers(GetUsersInput input)
        {
            var query = _userRepository.Table;
            if (!string.IsNullOrWhiteSpace(input.NameKeyWords))
                query = query.Where(m => m.UserName.Contains(input.NameKeyWords) || m.NickName.Contains(input.NameKeyWords) || m.TrueName.Contains(input.NameKeyWords));
            if (!string.IsNullOrWhiteSpace(input.EmailAddress))
                query = query.Where(n => n.AccountEmail.Contains(input.EmailAddress));
            if (input.IsActive.HasValue)
                query = query.Where(n => n.IsActived == input.IsActive.Value);
            var source = query.OrderBy(n => n.Id)
                              .Skip((input.PageIndex - 1) * input.PageSize)
                              .Take(input.PageSize)
                              .MapTo<List<UserDto>>();

            var result = new PagingList<UserDto>(source, input.PageIndex, input.PageSize,query.LongCount());
            return result;
        }
        /// <summary>
        ///     用户管理
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页数据数</param>
        /// <returns></returns>
        public virtual ActionResult ManageUsers(int pageIndex = 1, int pageSize = 5)
        {
            #region 组装搜索条件

            var input = new GetUsersInput
            {
                PageIndex = pageIndex,
                PageSize = pageSize,
                NameKeyWords = Request.QueryString.Get("NameKeyWords", string.Empty),
                EmailAddress = Request.QueryString.Get("EmailAddress", string.Empty),
                IsActive = Request.QueryString.Get<bool?>("IsActive", null)
            };

            #endregion

            #region 组装搜索下拉列表

            var activatedValues = new Dictionary<bool, string> {{true, "已激活"}, {false, "未激活"}};
            ViewData["IsActived"] =
                new SelectList(activatedValues.Select(n => new {text = n.Value, value = n.Key.ToString().ToLower()}),
                    "value", "text", input.IsActive);

            #endregion

            var user = _userService.GetUsers(input);

            return View(user);
        }