public List <EmployeeFilterDto> GetEmpFilter(EmployeeFilterDto obj) { var EmpList = (from emp in _context.Employee join dep in _context.Department on emp.DepartmentID equals dep.DepartmentID into g from m in g.DefaultIfEmpty() where (obj.EmployeeID > 0 ? emp.EmployeeID == obj.EmployeeID : emp.EmployeeID == emp.EmployeeID) && (!string.IsNullOrEmpty(obj.FirstName) ? emp.FirstName.Contains(obj.FirstName) : emp.FirstName == emp.FirstName) && (!string.IsNullOrEmpty(obj.LastName) ? emp.LastName.Contains(obj.LastName) : emp.LastName == emp.LastName) && (!string.IsNullOrEmpty(obj.DepartmentName) ? m.DepartmentName.Contains(obj.DepartmentName) : m.DepartmentName == m.DepartmentName) //!string.IsNullOrEmpty(obj.FirstName) ? emp.FirstName == obj.FirstName : emp.FirstName == emp.FirstName select new EmployeeFilterDto { EmployeeID = emp.EmployeeID, FirstName = emp.FirstName, LastName = emp.LastName, //EmailID = emp.EmailID, DepartmentName = m.DepartmentName, //ManagerName = m.FirstName }).OrderBy(o => o.FirstName).ToList(); //List<EmployeesListDTO> lists = EmpList.ToList(); return(EmpList); }
public ActionResult <List <EmployeeFilterDto> > EmployeeFilterAsync([FromBody] EmployeeFilterDto objEmployee) { if (string.IsNullOrEmpty(objEmployee.EmployeeID.ToString()) && string.IsNullOrEmpty(objEmployee.FirstName) && string.IsNullOrEmpty(objEmployee.LastName.ToString()) && string.IsNullOrEmpty(objEmployee.DepartmentName.ToString())) { return(BadRequest("Minimum one of the above field is mandatory for the filter criteria")); } return(_repo.GetEmpFilter(objEmployee)); }
public async Task <IResult> GetAllWithFilterAsync(EmployeeFilterDto filter) { var sortCriteria = new List <SortModel>(); var sort = new SortModel(); sortCriteria.Add(sort); var query = await UnitOfWork.Repository.FindAsync(PredicateBuilderFunction(filter), sortCriteria); var data = Mapper.Map <IEnumerable <EmployeeDto> >(query); return(ResponseResult.PostResult(data, status: HttpStatusCode.OK, message: HttpStatusCode.OK.ToString())); }
static Expression <Func <Entities.Employee, bool> > PredicateBuilderFunction(EmployeeFilterDto filter) { var predicate = PredicateBuilder.New <Entities.Employee>(true); if (!string.IsNullOrWhiteSpace(filter.JobTitle)) { predicate = predicate.And(b => b.JobTitle.ToLower().Contains(filter.JobTitle.ToLower())); } if (filter.Salary != null) { predicate = predicate.And(b => b.Salary == filter.Salary); } return(predicate); }
protected override IQuery <Employee> ApplyWhereClause(IQuery <Employee> query, EmployeeFilterDto filter) { if (filter.Email.IsNullOrEmpty()) { if (filter.CompanyId == 0) { return(query); } else { return(query.Where(new SimplePredicate(nameof(Employee.CompanyId), ValueComparingOperator.Equal, filter.CompanyId))); } } else { if (filter.CompanyId == 0) { return(query.Where(new SimplePredicate(nameof(Employee.Email), ValueComparingOperator.Equal, filter.Email))); } else { return(query.Where( new CompositePredicate(new List <IPredicate>() { new SimplePredicate(nameof(Employee.Email), ValueComparingOperator.Equal, filter.Email), new SimplePredicate(nameof(Employee.CompanyId), ValueComparingOperator.Equal, filter.CompanyId) }, LogicalOperator.AND) )); } } }
public async Task <IResult> GetPagedAsync([FromBody] EmployeeFilterDto filter) { return(await _service.GetAllWithFilterAsync(filter)); }