public Task Handle(InvestmentToolPriceChangedIntegrationEvent @event) { _logger.LogInformation($"Handling {nameof(InvestmentToolPriceChangedIntegrationEvent)} for {@event.InvestmentTool.Code}..."); var investmentToolPrice = new InvestmentToolPrice(@event.InvestmentTool.Key, @event.PriceDate, @event.InvestmentTool, @event.SalesPrice, @event.BuyingPrice); return(_repository.SaveAsync(investmentToolPrice)); }
public async Task Handle(ForeignCurrencyPriceChangedIntegrationEvent @event) { _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); var price = (await _investmentToolPriceRepository .FindAsync(p => p.InvestmentTool.Code == @event.CurrencyCode && p.PriceDate.Date == @event.PriceDate.Date)).FirstOrDefault(); if (price != null) { price.UpdatePrices(@event.SalesPrice, @event.BuyingPrice); _investmentToolPriceRepository.Update(price); } else { var investmentToolId = (await _investmentToolRepository.FindByCodeAsync(@event.CurrencyCode))?.Id; if (investmentToolId != null) { price = new InvestmentToolPrice(@event.PriceDate.Date, investmentToolId.Value, @event.SalesPrice, @event.BuyingPrice); _investmentToolPriceRepository.Add(price); } else { _logger.LogError("Could not found Currency Code {@currencyCode}. Prices will not insert to database.", @event.CurrencyCode); } } if (price != null) { await _investmentToolPriceRepository.UnitOfWork.SaveEntitiesAsync(); _logger.LogInformation("Prices for the Currency {currencyCode} successfully updated...", @event.CurrencyCode); } }