public async Task <object> GetAllEmployee(SearchCriteriaViewModel serachViewModel)
        {
            var Employee = (from EmployeeObj in _context.Employee.Where(b => (string.IsNullOrEmpty(serachViewModel.SearchText) ? true : (b.Name.Contains(serachViewModel.SearchText)) || b.Department.Name.Contains(serachViewModel.SearchText)) &&
                                                                        b.IsActive == true).OrderBy(b => b.Name)
                            select new EmployeeViewModel
            {
                Id = EmployeeObj.Id,
                Name = EmployeeObj.Name,
                Mobile = EmployeeObj.Mobile,
                Email = EmployeeObj.Email,
                DepartmentId = EmployeeObj.DepartmentId,
                DepartmentName = EmployeeObj.Department != null ? EmployeeObj.Department.Name :"",
                Age = EmployeeObj.Age,
                IsActive = EmployeeObj.IsActive,
                IsManager = EmployeeObj.Department != null && EmployeeObj.Department.ManagerId != null ? EmployeeObj.Department.ManagerId == EmployeeObj.Id ?true:false: false
            });

            var fieldName = "";

            if (!string.IsNullOrEmpty(serachViewModel.FieldName))
            {
                fieldName = StringExtensions.FirstCharToUpper(serachViewModel.FieldName);
            }
            var orderdEmployeeList = Employee;

            if (serachViewModel.OrderingProperty == OrderingProperty.Ascending)
            {
                if (!string.IsNullOrEmpty(serachViewModel.FieldName))
                {
                    orderdEmployeeList = StringFieldNameSortingSupport.OrderBy(Employee.AsQueryable(), fieldName);
                }
            }
            else if (serachViewModel.OrderingProperty == OrderingProperty.Descending)
            {
                if (!string.IsNullOrEmpty(serachViewModel.FieldName))
                {
                    orderdEmployeeList = StringFieldNameSortingSupport.OrderByDescending(Employee.AsQueryable(), fieldName);
                }
            }
            else
            {
                orderdEmployeeList = Employee.OrderByDescending(b => b.Id);
            }


            int Count     = orderdEmployeeList.Count();
            var PagedList = await orderdEmployeeList.ToPagedList((int)serachViewModel.PageNumber, (int)serachViewModel.PageSize).ToListAsync();

            var data = new
            {
                EmployeePagedList = PagedList,
                EmployeeCount     = Count
            };

            return(data);
        }
Example #2
0
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="loginKey">登录凭证</param>
        /// <param name="err">错误信息</param>
        /// <param name="pageIndex">当前页数</param>
        /// <param name="pageSize">页面大小</param>
        /// <param name="whereLambda">条件lambda表达表</param>
        /// <param name="orderField">排序字段</param>
        /// <param name="orderBy">排序方式</param>
        /// <returns>返回满足条件的泛型</returns>
        public IList <ProInterface.Models.LOGIN> Login_Where(string loginKey, ref ProInterface.ErrorInfo err, int pageIndex, int pageSize, string whereLambda, string orderField, string orderBy)
        {
            if (!GlobalFun.UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(null);
            }
            if (pageIndex < 1)
            {
                pageIndex = 1;
            }
            if (pageSize < 1)
            {
                pageSize = 1;
            }
            int skipCount = (pageIndex - 1) * pageSize;

            if (orderField == null || orderField == "")
            {
                err.IsError = true;
                err.Message = "排序表态式不能为空";
                return(null);
            }
            using (DBEntities db = new DBEntities())
            {
                var allList = db.fa_login.AsQueryable();
                if (whereLambda != null && whereLambda != "")
                {
                    try
                    {
                        Expression <Func <fa_login, bool> > whereFunc = StringToLambda.LambdaParser.Parse <Func <fa_login, bool> >(whereLambda);
                        allList = db.fa_login.Where(whereFunc);
                    }
                    catch
                    {
                        err.IsError = true;
                        err.Message = "条件表态式有误";
                        return(null);
                    }
                }

                if (orderBy == "asc")
                {
                    allList = StringFieldNameSortingSupport.OrderBy(allList, orderField);
                }
                else
                {
                    allList = StringFieldNameSortingSupport.OrderByDescending(allList, orderField);
                }

                var content = allList.Skip(skipCount).Take(pageSize).ToList();
                return(Fun.ClassListToCopy <fa_login, ProInterface.Models.LOGIN>(content));
            }
        }
        public async Task <object> GetAllDepartment(SearchCriteriaViewModel serachViewModel)
        {
            var Department = (from DepartmentObj in _context.Department.Where(b => (string.IsNullOrEmpty(serachViewModel.SearchText) ? true : b.Name.Contains(serachViewModel.SearchText)) &&
                                                                              b.IsActive == true).OrderBy(b => b.Name)
                              select new DepartmentViewModel
            {
                Id = DepartmentObj.Id,
                Name = DepartmentObj.Name,
                Manager = DepartmentObj.ManagerId
            })
            ;

            var fieldName = "";

            if (!string.IsNullOrEmpty(serachViewModel.FieldName))
            {
                fieldName = StringExtensions.FirstCharToUpper(serachViewModel.FieldName);
            }
            var orderdDepartmentList = Department;

            if (serachViewModel.OrderingProperty == OrderingProperty.Ascending)
            {
                if (!string.IsNullOrEmpty(serachViewModel.FieldName))
                {
                    orderdDepartmentList = StringFieldNameSortingSupport.OrderBy(Department.AsQueryable(), fieldName);
                }
            }
            else if (serachViewModel.OrderingProperty == OrderingProperty.Descending)
            {
                if (!string.IsNullOrEmpty(serachViewModel.FieldName))
                {
                    orderdDepartmentList = StringFieldNameSortingSupport.OrderByDescending(Department.AsQueryable(), fieldName);
                }
            }
            else
            {
                orderdDepartmentList = Department.OrderByDescending(b => b.Id);
            }


            int Count     = orderdDepartmentList.Count();
            var PagedList = await orderdDepartmentList.ToPagedList((int)serachViewModel.PageNumber, (int)serachViewModel.PageSize).ToListAsync();

            var data = new
            {
                DepartmentPagedList = PagedList,
                DepartmentCount     = Count
            };

            return(data);
        }
Example #4
0
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="loginKey">登录凭证</param>
        /// <param name="err">错误信息</param>
        /// <param name="pageIndex">当前页数</param>
        /// <param name="pageSize">页面大小</param>
        /// <param name="whereLambda">条件lambda表达表</param>
        /// <param name="orderField">排序字段</param>
        /// <param name="orderBy">排序方式</param>
        /// <returns>返回满足条件的泛型</returns>
        public IList <ProInterface.Models.MODULE> SysModuleWhere(string loginKey, ref ProInterface.ErrorInfo err, int pageIndex, int pageSize, string whereLambda, string orderField, string orderBy)
        {
            if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(null);
            }
            GlobalUser gu = Global.GetUser(loginKey);

            if (gu == null)
            {
                err.IsError = true;
                err.Message = "登录超时";
                return(null);
            }

            if (pageIndex < 1)
            {
                pageIndex = 1;
            }
            if (pageSize < 1)
            {
                pageSize = 1;
            }
            int skipCount = (pageIndex - 1) * pageSize;

            if (orderField == null || orderField == "")
            {
                err.IsError = true;
                err.Message = "排序表态式不能为空";
                return(null);
            }
            using (DBEntities db = new DBEntities())
            {
                var allList = db.YL_MODULE.Where(x => x.YL_ROLE.Where(y => gu.RoleID.Contains(y.ID)).Count() > 0).AsQueryable();
                if (whereLambda != null && whereLambda != "")
                {
                    try
                    {
                        Expression <Func <YL_MODULE, bool> > whereFunc = StringToLambda.LambdaParser.Parse <Func <YL_MODULE, bool> >(whereLambda);
                        allList = allList.Where(whereFunc);
                    }
                    catch
                    {
                        err.IsError = true;
                        err.Message = "条件表态式有误";
                        return(null);
                    }
                }

                if (orderBy == "asc")
                {
                    allList = StringFieldNameSortingSupport.OrderBy(allList, orderField);
                }
                else
                {
                    allList = StringFieldNameSortingSupport.OrderByDescending(allList, orderField);
                }

                var content = allList.Skip(skipCount).Take(pageSize).ToList();
                return(Fun.ClassListToCopy <YL_MODULE, ProInterface.Models.MODULE>(content));
            }
        }