public bool Handle(DomainEventHandlerData <RevenueCointEvent> @event) { var snap = @event.Snapshot as GameAggregate; if (snap == null) { return(false); } var relateEvents = new List <EventBase>(); var userCastles = snap.Castles.Where(e => e.OwnerUserId == snap.UserId).ToList() ?? new List <CastleAggregate>(); foreach (var castle in userCastles) { var coins = _gameDomainService.CalculateCoin(snap, castle); snap.UserCoins += coins; relateEvents.Add(new CastleRevenueCointEvent(castle.Id, coins, snap.UserId, DateTime.UtcNow, DateTime.UtcNow)); //var createSoldier = _gameDomainService.GetCreateSoldierIfNeedCreate(snap, castle); //if (createSoldier != null) // relateEvents.Add(createSoldier); } var opponentCastles = snap.Castles.Where(e => e.OwnerUserId == snap.OpponentId).ToList() ?? new List <CastleAggregate>(); foreach (var castle in opponentCastles) { var coins = _gameDomainService.CalculateCoin(snap, castle); snap.OpponentCoins += coins; relateEvents.Add(new CastleRevenueCointEvent(castle.Id, coins, snap.OpponentId, DateTime.UtcNow, DateTime.UtcNow)); //var createSoldier = _gameDomainService.GetCreateSoldierIfNeedCreate(snap, castle); //if (createSoldier != null) // relateEvents.Add(createSoldier); } relateEvents.Add(_gameDomainService.RevenueCoinEvent(snap.Speed)); _domainService.AddEvent(snap.Id, relateEvents.ToArray()); return(true); }