public async Task <IActionResult> SearchEmployees(MdlSearchEmp objEmp) { var result = await _iEmpRepo.SearchEmployee(objEmp); if (result != null && result.Count() > 0) { return(this.StatusCode(StatusCodes.Status200OK, result)); } else { return(this.StatusCode(StatusCodes.Status404NotFound, "Not Found.")); } }
public async Task <IEnumerable <MdlSearchEmp> > SearchEmployee(MdlSearchEmp objEmp) { string strQuery = "select * from Employee"; string strFilter = ""; if (objEmp.Id > 0) { strFilter += string.IsNullOrEmpty(strFilter) ? "Id = @Id " : "and Id = @Id "; } if (!string.IsNullOrEmpty(objEmp.FName)) { strFilter += string.IsNullOrEmpty(strFilter) ? "FName like @FName " : "and FName like @FName "; } if (!string.IsNullOrEmpty(objEmp.LName)) { strFilter += string.IsNullOrEmpty(strFilter) ? "LName like @LName " : "and LName like @LName "; } if (!string.IsNullOrEmpty(objEmp.Designation)) { strFilter += string.IsNullOrEmpty(strFilter) ? "Designation like @Designation " : "and Designation like @Designation "; } if (!string.IsNullOrEmpty(objEmp.Email)) { strFilter += string.IsNullOrEmpty(strFilter) ? "Email like @Email " : "and Email like @Email "; } if (!string.IsNullOrEmpty(objEmp.Gender)) { strFilter += string.IsNullOrEmpty(strFilter) ? "Gender like @Gender " : "and Gender like @Gender "; } strFilter = !string.IsNullOrEmpty(strFilter) ? " Where " + strFilter : ""; strQuery = strQuery + strFilter + " order by 2 desc"; return(await Task.Run(() => _dbConnection.Query <MdlSearchEmp>(strQuery, new { FName = "%" + objEmp.FName + "%", LName = "%" + objEmp.LName + "%", Designation = "%" + objEmp.Designation + "%", Email = "%" + objEmp.Email + "%", Gender = "%" + objEmp.Gender + "%" }).ToList())); }