コード例 #1
0
        public async Task Handle(InvestmentForcedCloseDomainEvent notification, CancellationToken cancellationToken)
        {
            var investment = notification.Investment;
            var roundtrips = await _roundtripRepository.GetByInvestmentId(investment.InvestmentId);

            if (roundtrips.Any())
            {
                foreach (var roundtrip in roundtrips)
                {
                    if (roundtrip.GetStatus().Id != RoundtripStatus.Exit.Id && roundtrip.GetStatus().Id != RoundtripStatus.ForceExit.Id)
                    {
                        roundtrip.ForceSelling();
                    }
                    _roundtripRepository.Update(roundtrip);
                }
            }

            try
            {
                await this._roundtripRepository.UnitOfWork.SaveEntitiesAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Handle Domain Event: InvestmentForcedCloseDomainEvent.");
                Console.WriteLine("Result: Failure.");
                Console.WriteLine("Error Message: " + ex.Message);
            }
        }
        public async Task Handle(NextTargetPriceGeneratedIntegrationEvent @event)
        {
            try
            {
                var roundtrip = await _roundtripRepository.GetByRoundtripId(@event.RoundtripId);

                if (roundtrip == null)
                {
                    return;
                }

                roundtrip.MoveTargetPrice(@event.NextTargetPrice);

                _roundtripRepository.Update(roundtrip);

                await _roundtripRepository.UnitOfWork.SaveEntitiesAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Handle Integration Event: NextTargetPriceGeneratedIntegrationEvent.");
                Console.WriteLine("Result: Failure.");
                Console.WriteLine("Error Message: " + ex.Message);
            }
        }