using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Volo.Abp; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Volo.Abp.AuditLogging; using Volo.Abp.Uow; using static Sozsoft.Platform.Data.Seeds.SeedConsts; namespace Sozsoft.Platform.AuditLogs; public interface IAuditLogAppService : ICrudAppService { } [Authorize(AppCodes.IdentityManagement.AuditLogs)] public class AuditLogAppService : CrudAppService , IAuditLogAppService { public AuditLogAppService(IAuditLogRepository auditLogRepository) : base(auditLogRepository) { } public override async Task GetAsync(Guid id) { var entity = await Repository.GetAsync(id, includeDetails: true); return await MapToGetOutputDtoAsync(entity); } [UnitOfWork] public override async Task> GetListAsync(PagedAndSortedResultRequestDto input) { var query = await CreateFilteredQueryAsync(input); var totalCount = await AsyncExecuter.CountAsync(query); query = ApplySorting(query, input); query = ApplyPaging(query, input); // EntityChanges ile birlikte getir (N+1 query önlenir) var auditLogRepository = (IAuditLogRepository)Repository; var auditLogsWithDetails = await auditLogRepository.GetListAsync( sorting: input.Sorting, maxResultCount: input.MaxResultCount, skipCount: input.SkipCount, includeDetails: true ); // Mapping tek seferde yap var entityDtos = ObjectMapper.Map, List>(auditLogsWithDetails); // EntityChangeCount'u doldur (artık EntityChanges yüklü) foreach (var dto in entityDtos) { var auditLog = auditLogsWithDetails.FirstOrDefault(a => a.Id == dto.Id); dto.EntityChangeCount = auditLog?.EntityChanges?.Count ?? 0; } return new PagedResultDto( totalCount, entityDtos ); } // Audit Log kayitlarini gormek istiyoruz fakat degistirmek istemiyoruz [RemoteService(IsEnabled = false)] public override Task CreateAsync(AuditLogDto input) { return null; } [RemoteService(IsEnabled = false)] public override Task UpdateAsync(Guid id, AuditLogDto input) { return null; } [RemoteService(IsEnabled = false)] public override Task DeleteAsync(Guid id) { return null; } }