IAggregateInfoConstructor IGetAccountByIdGateway.GetAccountById(string accountId) { var aggregate = _context.Aggregates.ToList().DefaultIfEmpty(null).SingleOrDefault(b => b.Id == accountId); if (aggregate == null) { throw new InvalidOperationException(); } var events = _context.Events.ToList().Where(x => x.AggregateId == accountId).OrderBy(x => x.AggregateVersion); return(new AggregateInfoConstructor { AggregateId = aggregate.Id, AggregateBaseVersion = aggregate.LastVersion, Events = EventsMapper.EventsMapperRepositoryToIEvents(events) }); }
public async Task <IAggregateInfoConstructor> GetAccountById(string accountId) { //if(!_context.Aggregates.Any()) // throw new InvalidOperationException(); var aggregate = await _context.Aggregates.FindAsync(accountId); if (aggregate == null) { throw new InvalidOperationException(); } var events = await _context.Events.Where(x => x.AggregateId == accountId).OrderBy(x => x.AggregateVersion).ToListAsync(); return(new AggregateInfoConstructor { AggregateId = aggregate.Id, AggregateBaseVersion = aggregate.LastVersion, Events = EventsMapper.EventsMapperRepositoryToIEvents(events) }); }