コード例 #1
0
        public async Task <List <AuditLogEntryDTO> > HandleAsync(GetAuditEntriesQuery queryOptions, CancellationToken cancellationToken = default)
        {
            var query = _dbContext.Set <AuditLogEntry>() as IQueryable <AuditLogEntry>;

            if (queryOptions.UserId != Guid.Empty)
            {
                query = query.Where(x => x.UserId == queryOptions.UserId);
            }

            if (!string.IsNullOrEmpty(queryOptions.ObjectId))
            {
                query = query.Where(x => x.ObjectId == queryOptions.ObjectId);
            }

            if (queryOptions.AsNoTracking)
            {
                query = query.AsNoTracking();
            }

            var auditLogs = await query.ToListAsync();

            var users = await _dispatcher.DispatchAsync(new GetUsersQuery(), cancellationToken);

            var rs = auditLogs.Join(users, x => x.UserId, y => y.Id,
                                    (x, y) => new AuditLogEntryDTO
            {
                Id              = x.Id,
                UserId          = x.UserId,
                Action          = x.Action,
                ObjectId        = x.ObjectId,
                Log             = x.Log,
                CreatedDateTime = x.CreatedDateTime,
                UserName        = y.UserName,
            });

            return(rs.OrderByDescending(x => x.CreatedDateTime).ToList());
        }
コード例 #2
0
 public StorageRepositoryAsync(StorageDbContext dbContext) : base(dbContext)
 {
     _items = dbContext.Set <Item>();
 }
 public virtual async ValueTask <T> GetByIdAsync(int id)
 {
     Console.WriteLine($"tryying to find file with id {id}");
     return(await _dbContext.Set <T>().FindAsync(id));
 }
コード例 #4
0
 public BaseRepository(StorageDbContext context)
 {
     this.context = context;
     this.dbSet   = context.Set <TEntity>();
 }