Beispiel #1
0
        public async Task <IActionResult> Index(AuditLogSelectDto selectDto)
        {
            var logs = await _auditLogAppService.GetAuditLogs(selectDto);

            ViewBag.Page       = selectDto.Page;
            ViewBag.PageSize   = selectDto.PageSize;
            ViewBag.TotalCount = logs.TotalCount;
            return(View(logs));
        }
Beispiel #2
0
        public async Task <PagedResultDto <AuditLogListDto> > GetAuditLogs(AuditLogSelectDto input)
        {
            var query = _auditLogRepository
                        .GetAll()
                        .WhereIf(input.UserId.HasValue, p => p.UserId.Value == input.UserId)
                        .WhereIf(input.IsException.HasValue, p => input.IsException.Value ? p.Exception != null : p.Exception == null)
                        .WhereIf(!string.IsNullOrEmpty(input.ServerName), p => p.ServiceName.Contains(input.ServerName))
                        .WhereIf(!string.IsNullOrEmpty(input.MethodName), p => p.MethodName.Contains(input.MethodName))
                        .WhereIf(!string.IsNullOrEmpty(input.Ip), p => p.ClientIpAddress.Contains(input.Ip))
                        .WhereIf(input.MaxExecutionDuration.HasValue, p => p.ExecutionDuration <= input.MaxExecutionDuration)
                        .WhereIf(input.MinExecutionDuration.HasValue, p => p.ExecutionDuration >= input.MinExecutionDuration)
                        .WhereIf(input.StartTime.HasValue, p => p.ExecutionTime >= input.StartTime)
                        .WhereIf(input.EndTime.HasValue, p => p.ExecutionTime <= input.EndTime);
            var logs = await query
                       .OrderByDescending(p => p.ExecutionTime)
                       .WherePaging(input)
                       .ToListAsync();

            int count = await query.CountAsync();

            return(new PagedResultDto <AuditLogListDto>(count, ObjectMapper.Map <List <AuditLogListDto> >(logs)));
        }