public async Task <IActionResult> GetPagedAudit([FromQuery] AuditParams auditParams) { var audits = await auditRepository.GetPagedAudit(auditParams); var result = mapper.Map <IEnumerable <ViewAuditResource> >(audits); Response.AddPagination(audits.CurrentPage, audits.PageSize, audits.TotalCount, audits.TotalPages); return(Ok(result)); }
public async Task <PagedList <Audit> > GetPagedAudit(AuditParams auditParams) { var audit = context.Audit.AsQueryable(); if (DateTime.Compare(auditParams.Date, new DateTime(01, 1, 1)) != 0) { audit = audit.Where(a => a.DateTime.Date == auditParams.Date.Date); } if (auditParams.UserId > 0) { audit = audit.Where(a => a.UserId == auditParams.UserId); } if (!string.IsNullOrEmpty(auditParams.TableName)) { audit = audit.Where(a => a.TableName == auditParams.TableName); } //name,sort if (auditParams.isDescending) { if (!string.IsNullOrEmpty(auditParams.OrderBy)) { switch (auditParams.OrderBy.ToLower()) { case "date": audit = audit.OrderByDescending(a => a.DateTime); break; case "tabelname": audit = audit.OrderByDescending(a => a.TableName); break; case "userid": audit = audit.OrderByDescending(a => a.UserId); break; default: audit = audit.OrderByDescending(a => a.DateTime); break; } } else { audit = audit.OrderByDescending(a => a.DateTime); } } else { if (!string.IsNullOrEmpty(auditParams.OrderBy)) { switch (auditParams.OrderBy.ToLower()) { case "date": audit = audit.OrderBy(a => a.DateTime); break; case "tablename": audit = audit.OrderBy(a => a.TableName); break; case "userid": audit = audit.OrderBy(a => a.UserId); break; default: audit = audit.OrderBy(a => a.DateTime); break; } } else { audit = audit.OrderBy(a => a.DateTime); } } return(await PagedList <Audit> .CreateAsync(audit, auditParams.PageNumber, auditParams.PageSize)); }