Ejemplo n.º 1
0
        public ApiReturns Get(GetPageParams param)
        {
            var page = param.page;
            var size = param.size;
            var name = param.conditions.Value <string>("name");

            Expression <Func <Department, bool> > predicate;

            if (string.IsNullOrEmpty(name))
            {
                predicate = d => d.IsDeleted == false;
            }
            else
            {
                predicate = d => d.IsDeleted == false && d.Name.Contains(name);
            }

            var totalCount = _departmentBll.GetTotalCount(predicate);
            var list       = _departmentBll.QueryList(predicate)
                             .OrderByDescending(d => d.AddTime)
                             .Skip((page - 1) * size)
                             .Take(size);

            return(ApiReturns.Ok(new { total = totalCount, list }));
        }
Ejemplo n.º 2
0
        public ApiReturns GetPage(GetPageParams param)
        {
            if (!ModelState.IsValid)
            {
                return(ApiReturns.BadRequest());
            }

            var name     = param.conditions.Value <string>("name");
            var departId = param.conditions.Value <int>("departId");
            var userType = param.conditions.Value <int>("userType");

            var list = _viewPersonBll.QueryList(p => p.IsDeleted == false);

            #region 条件过滤
            // 条件查询
            if (LoginStatus.IsSuperAdminLogin())
            {
                if (departId > 0)
                {
                    list = list.Where(p => p.DepartmentId == departId);
                }
                if (userType >= 0)
                {
                    list = list.Where(p => p.UserType == userType);
                }
            }
            else
            {
                // 一般管理员登录,仅查询其所属单位的人员信息
                var user = LoginStatus.GetLoginUser();
                list = list.Where(p => p.DepartmentId == user.DepartmentId);
            }

            if (!string.IsNullOrEmpty(name))
            {
                list = list.Where(p => p.Name.Contains(name) || p.WorkNo.Contains(name));
            }
            #endregion

            // 分页
            list = list.OrderByDescending(p => p.Id)
                   .Skip((param.page - 1) * param.size)
                   .Take(param.size);
            var total = list.Count();

            return(ApiReturns.Ok(new { total, list }));
        }