public static string WhereString(PaginationBy paginationBy) { StringBuilder sbWhr = new StringBuilder(); foreach (var vAry in paginationBy.searchBy) { sbWhr.AppendFormat("{0} {1} {2} {3} ", vAry.FieldName, vAry.Parameter, vAry.FieldValue, vAry.ConditionWith); } return(sbWhr.ToString()); }
//[TypeFilter(typeof(ActionFilters.RolesValidate), Arguments = new object[] { "Employee", EnumPermission.View })] public async Task <IActionResult> GetBy(PaginationBy searchBy) { ResponseHelper objHelper = new ResponseHelper(); try { var vList = await paginatedQueryRepo.GetPaginated(searchBy); objHelper.Status = StatusCodes.Status200OK; objHelper.Message = "Get Successfully"; objHelper.Data = vList; return(Ok(objHelper)); } catch (Exception ex) { objHelper.Status = StatusCodes.Status500InternalServerError; objHelper.Message = ex.Message; return(StatusCode(StatusCodes.Status500InternalServerError, objHelper)); } }
public async Task <ReturnBy <Employee> > GetPaginated(PaginationBy search) { try { string strOrder = string.IsNullOrEmpty(search.OrderBy) ? "Emp_Id" : search.OrderBy; string strWhere = Common.Search.WhereString(search); IEnumerable <Employee> vEmployee; if (!String.IsNullOrEmpty(search.CommonSearch)) { vEmployee = adbContext.employee.Where(w => new[] { w.Emp_Code, Convert.ToString(w.Emp_Id), Convert.ToString(w.Company_Id), Convert.ToString(w.Site_Id), Convert.ToString(w.JD_Id), Convert.ToString(w.Dept_Id), Convert.ToString(w.Desig_Id), Convert.ToString(w.Zone_Id), Convert.ToString(w.Shift_Id) }.Any(a => a.Contains(search.CommonSearch.ToLower()))).OrderBy(strOrder).ToList(); } else { vEmployee = adbContext.employee.Where(strWhere).OrderBy(strOrder).ToList(); } ReturnBy <Employee> vList = new ReturnBy <Employee>() { list = vEmployee.Skip(search.PageIndex * search.PageSize).Take(search.PageSize).ToList(), RecordCount = vEmployee.Count() }; if (vList.list == null || vList.RecordCount == 0) { throw new RecoredNotFoundException("Get Data Empty"); } return(await Task.FromResult(vList)); } catch (Exception ex) { throw ex; } }