diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/Paging/PagedResult.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/Paging/PagedResult.cs deleted file mode 100644 index 49e51eb078..0000000000 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/Paging/PagedResult.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Volo.Abp.Paging -{ - public class PagedResult : ListResultDto, IPagedResult - { - /// - public long TotalCount { get; set; } - - /// - /// Creates a new object. - /// - public PagedResult() - { - - } - - /// - /// Creates a new object. - /// - /// Total count of Items - /// List of items in current page - public PagedResult(long totalCount, IReadOnlyList items) - : base(items) - { - TotalCount = totalCount; - } - } - - public class ListResultDto : IListResult - { - /// - public IReadOnlyList Items - { - get { return _items ?? (_items = new List()); } - set { _items = value; } - } - private IReadOnlyList _items; - - /// - /// Creates a new object. - /// - public ListResultDto() - { - - } - - /// - /// Creates a new object. - /// - /// List of items - public ListResultDto(IReadOnlyList items) - { - Items = items; - } - } - - public interface IListResult - { - IReadOnlyList Items { get; set; } - } - - public interface IPagedResult : IListResult, IHasTotalCount - { - } - - public interface IHasTotalCount - { - long TotalCount { get; set; } - } -} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs index 53b278ae5d..f02d84102e 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Net; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; @@ -7,15 +8,21 @@ namespace Volo.Abp.AuditLogging { public interface IAuditLogRepository : IBasicRepository { - Task> GetListAsync( + Task> GetListAsync( string sorting = null, int maxResultCount = 50, int skipCount = 0, - string filter = null, string httpMethod = null, string url = null, string userName = null, HttpStatusCode? httpStatusCode = null, bool includeDetails = false); + + Task GetCountAsync( + string httpMethod = null, + string url = null, + string userName = null, + HttpStatusCode? httpStatusCode = null, + bool includeDetails = true); } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs index c0bb68d835..5e5dbe6d9b 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Linq.Dynamic.Core; using System.Net; @@ -17,31 +18,52 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore } - public async Task> GetListAsync( + public async Task> GetListAsync( string sorting = null, int maxResultCount = 50, int skipCount = 0, - string filter = null, string httpMethod = null, string url = null, string userName = null, HttpStatusCode? httpStatusCode = null, - bool includeDetails = false) + bool includeDetails = true) { - var query = DbSet.AsNoTracking() - .IncludeDetails(includeDetails) - .WhereIf(httpMethod != null, auditLog => auditLog.HttpMethod != null && auditLog.HttpMethod.ToLowerInvariant() == httpMethod.ToLowerInvariant()) - .WhereIf(url != null, auditLog => auditLog.Url != null && auditLog.Url.ToLowerInvariant().Contains(url.ToLowerInvariant())) - .WhereIf(userName != null, auditLog => auditLog.UserName != null && auditLog.UserName == userName) - .WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == (int?)httpStatusCode); - - var totalCount = await query.LongCountAsync(); + var query = GetListQuery(httpMethod, url, userName, httpStatusCode, includeDetails); var auditLogs = await query.OrderBy(sorting) .PageBy(skipCount, maxResultCount) .ToListAsync(); - return new Paging.PagedResult(totalCount, auditLogs); + return auditLogs; + } + + public async Task GetCountAsync( + string httpMethod = null, + string url = null, + string userName = null, + HttpStatusCode? httpStatusCode = null, + bool includeDetails = true) + { + var query = GetListQuery(httpMethod, url, userName, httpStatusCode, includeDetails); + + var totalCount = await query.LongCountAsync(); + + return totalCount; + } + + private IQueryable GetListQuery( + string httpMethod = null, + string url = null, + string userName = null, + HttpStatusCode? httpStatusCode = null, + bool includeDetails = true) + { + return DbSet.AsNoTracking() + .IncludeDetails(includeDetails) + .WhereIf(httpMethod != null, auditLog => auditLog.HttpMethod != null && auditLog.HttpMethod.ToLowerInvariant() == httpMethod.ToLowerInvariant()) + .WhereIf(url != null, auditLog => auditLog.Url != null && auditLog.Url.ToLowerInvariant().Contains(url.ToLowerInvariant())) + .WhereIf(userName != null, auditLog => auditLog.UserName != null && auditLog.UserName == userName) + .WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == (int?)httpStatusCode); } public override IQueryable WithDetails() diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs index 8c2f831e73..992da23369 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Linq.Dynamic.Core; using System.Net; @@ -18,22 +19,35 @@ namespace Volo.Abp.AuditLogging.MongoDB } - public async Task> GetListAsync(string sorting = null, int maxResultCount = 50, int skipCount = 0, string filter = null, + public async Task> GetListAsync(string sorting = null, int maxResultCount = 50, int skipCount = 0, string httpMethod = null, string url = null, string userName = null, HttpStatusCode? httpStatusCode = null, bool includeDetails = false) { - var query = GetMongoQueryable() - .WhereIf(httpMethod != null, auditLog => auditLog.HttpMethod != null && auditLog.HttpMethod.ToLowerInvariant() == httpMethod.ToLowerInvariant()) - .WhereIf(url != null, auditLog => auditLog.Url != null && auditLog.Url.ToLowerInvariant().Contains(url.ToLowerInvariant())) - .WhereIf(userName != null, auditLog => auditLog.UserName != null && auditLog.UserName == userName) - .WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == (int?)httpStatusCode); + var query = GetListQuery(httpMethod, url, userName, httpStatusCode, includeDetails); - var totalCount = await query.As>().LongCountAsync(); - - var questions = await query.OrderBy(sorting).As>() + return await query.OrderBy(sorting).As>() .PageBy>(skipCount, maxResultCount) .ToListAsync(); + } + + public async Task GetCountAsync(string httpMethod = null, string url = null, string userName = null, HttpStatusCode? httpStatusCode = null, bool includeDetails = false) + { + var query = GetListQuery(httpMethod, url, userName, httpStatusCode, includeDetails); - return new Paging.PagedResult(totalCount, questions); + return await query.As>().LongCountAsync(); + } + + private IQueryable GetListQuery( + string httpMethod = null, + string url = null, + string userName = null, + HttpStatusCode? httpStatusCode = null, + bool includeDetails = true) + { + return GetMongoQueryable() + .WhereIf(httpMethod != null, auditLog => auditLog.HttpMethod != null && auditLog.HttpMethod.ToLowerInvariant() == httpMethod.ToLowerInvariant()) + .WhereIf(url != null, auditLog => auditLog.Url != null && auditLog.Url.ToLowerInvariant().Contains(url.ToLowerInvariant())) + .WhereIf(userName != null, auditLog => auditLog.UserName != null && auditLog.UserName == userName) + .WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == (int?)httpStatusCode); } } }