using RSecurityBackend.DbContext; using RSecurityBackend.Models.Audit.Db; using RSecurityBackend.Models.Auth.Db; using RSecurityBackend.Models.Generic; using System; using System.Linq; using System.Threading.Tasks; namespace RSecurityBackend.Services.Implementation { /// /// Audit Log Service Implementation /// public class AuditLogServiceEF : IAuditLogService { /// /// get all audit logs ordered by time /// /// /// empty means unfiltered /// /// public async Task> GetAll(PagingParameterModel paging, string userName, bool orderByTimeDescending) { try { userName = userName == null ? "" : userName.Trim(); var source = orderByTimeDescending ? _context.AuditLogs .Where(l => string.IsNullOrEmpty(userName) || l.UserName == userName) .OrderByDescending(l => l.StartDate) .AsQueryable() : _context.AuditLogs .Where(l => string.IsNullOrEmpty(userName) || l.UserName == userName) .OrderBy(l => l.StartDate) .AsQueryable(); (PaginationMetadata PagingMeta, REvent[] Items) paginatedResult = await QueryablePaginator.Paginate(source, paging); return new RServiceResult<(PaginationMetadata PagingMeta, REvent[] Items)>(paginatedResult); } catch (Exception exp) { return new RServiceResult<(PaginationMetadata PagingMeta, REvent[] Items)>((PagingMeta: null, Items: null), exp.ToString()); } } /// /// Database Contetxt /// protected readonly RSecurityDbContext _context; /// /// constuctor /// /// public AuditLogServiceEF(RSecurityDbContext context) { _context = context; } } }