public async Task <Result> Handle(Query query, CancellationToken cancellationToken) { var users = await _context.QueryRepository <UserEntity, Guid>() .Queryable() .Select(x => new User() { Id = x.Id, Email = x.Email, FirstName = x.FirstName, LastName = x.LastName }).ToListAsync(cancellationToken: cancellationToken); var result = new Result() { Users = users }; return(result); }
public async Task <Result> Handle(Command command, CancellationToken cancellationToken) { var result = new Result(); var user = await _context.QueryRepository <UserEntity, Guid>() .Queryable() .FirstOrDefaultAsync(x => x.Id == command.Id, cancellationToken); if (user is null) { result.ResultMessage = "Unknown user identifier"; return(result); } await _context.RepositoryAsync <UserEntity, Guid>().DeleteAsync(user); var @event = Mapping.Map <UserEntity, UserDeletedEvent>(user); @event.UserId = user.Id; await _context.SaveChangesAsync(cancellationToken); await _eventBus.CommitAsync(@event); // await using var context = new UserDataContext(); // await using var transaction = await context.Database.BeginTransactionAsync(cancellationToken); // // try // { // await _context.SaveChangesAsync(cancellationToken); // // await _eventBus.CommitAsync(@event); // // await transaction.CommitAsync(cancellationToken); // } // catch (Exception) // { // await transaction.RollbackAsync(cancellationToken); // } return(result); }
public async Task <Result> Handle(Query query, CancellationToken cancellationToken) { var user = await _context .QueryRepository <UserEntity, Guid>() .Queryable() .Where(x => x.Id == query.Id) .Select(x => new Result() { Email = x.Email, FirstName = x.FirstName, LastName = x.LastName }) .FirstOrDefaultAsync(cancellationToken: cancellationToken); if (user is null) { throw new ArgumentNullException($"{nameof(user)} was not found by id '{query.Id}'"); } return(user); }
public IQueryable <SongEntity> Queryable() { return(_context.QueryRepository <SongEntity, Guid>().Queryable()); }
public IQueryable <TransactionEntity> GetQueryable() { var queryRepository = _efUnitOfWork.QueryRepository <TransactionEntity>(); return(queryRepository.Queryable()); }