public ActionResult List(EmployeeQueryParam queryParam) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); string sql = @"SELECT A.ID,A.uid,A.pwd,A.name,A.idcard,A.idcard,A.birthday,A.dptid,B.DeptName as dptname,A.postid,C.PositionName post,A.sex,A.tel,A.status,A.EntryDate,A.address,A.education,A.schools from HR_Employee A LEFT join TErp_Department B ON A.dptid=B.Id left join TErp_Position C ON A.postid=C.Id where (A.isDelete is null or A.isDelete = 0) "; if (!string.IsNullOrEmpty(queryParam.name)) { sql += string.Format("and A.name like {0}", SQLHelper.ToSQLParamLikeStr(queryParam.name)); } sql += "order by A.ID desc"; IPageList <HKSJRecruitment.Models.proModels.HR_Employee> dtoss = ctx.Database.SqlQuery <HKSJRecruitment.Models.proModels.HR_Employee>(sql).ToPagedList(queryParam.PageIndex, queryParam.PageSize); return(Content(this.GetJSON(new { total = dtoss.PageInfo.TotalCount, rows = dtoss }), this.JsonContentType())); }
public ActionResult ListEmployee(EmployeeQueryParam queryParam) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); Expression <Func <HR_Employee, bool> > predicate = c => c.isDelete == null || c.isDelete == 0; if (queryParam.deptid > 0) { predicate = predicate.And(c => c.dptid == queryParam.deptid); } if (!string.IsNullOrEmpty(queryParam.name)) { predicate = predicate.And(c => c.name.Contains(queryParam.name) || c.uid.Contains(queryParam.name)); } IPageList <EmployeeData> dtos = ctx.HR_Employee.Where(predicate).OrderBy(c => c.ID).Select(c => new EmployeeData { Id = c.ID, Name = c.name, Uid = c.uid }).ToPagedList(queryParam.PageIndex, queryParam.PageSize); return(Content(this.GetJSON(new { total = dtos.PageInfo.TotalCount, rows = dtos }), this.JsonContentType())); }