Task IEventHandler <CurrencyExchangeRateSet> .HandleAsync(CurrencyExchangeRateSet payload) { UserModel userModel = GetUserModel(payload.UserKey); userModel.ExchangeRateHashCodes.Add(payload.GetHashCode()); return(Task.CompletedTask); }
Task IEventHandler <CurrencyExchangeRateSet> .HandleAsync(CurrencyExchangeRateSet payload) { List <ExchangeRateModel> exchangeRates = currencies[payload.TargetUniqueCode]; exchangeRates.Add(new ExchangeRateModel(payload.SourceUniqueCode, payload.Rate, payload.ValidFrom)); exchangeRates.Sort(exchangeRateComparer); return(Task.CompletedTask); }
async Task IEventHandler <CurrencyExchangeRateSet> .HandleAsync(CurrencyExchangeRateSet payload) { await EnsureUserStorageAsync(payload.UserKey); List <ExchangeRateModel> exchangeRates = storage[payload.UserKey].Currencies[payload.TargetUniqueCode]; exchangeRates.Add(new ExchangeRateModel(payload.SourceUniqueCode, payload.Rate, payload.ValidFrom)); exchangeRates.Sort(exchangeRateComparer); }
async Task IEventHandler <CurrencyExchangeRateSet> .HandleAsync(CurrencyExchangeRateSet payload) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { CurrencyEditViewModel viewModel = ViewModel.Items.FirstOrDefault(c => c.UniqueCode == payload.TargetUniqueCode); if (viewModel != null) { viewModel.ExchangeRates.Add(new ExchangeRateModel( payload.SourceUniqueCode, payload.Rate, payload.ValidFrom )); viewModel.ExchangeRates.SortDescending(r => r.ValidFrom); } }); }
public async Task HandleAsync(CurrencyExchangeRateSet payload) { using (ReadModelContext db = readModelContextFactory.Create()) { await db.ExchangeRates.AddAsync( new CurrencyExchangeRateEntity() { TargetCurrency = payload.TargetUniqueCode, SourceCurrency = payload.SourceUniqueCode, Rate = payload.Rate, ValidFrom = payload.ValidFrom }.SetUserKey(payload.UserKey) ); await db.SaveChangesAsync(); } }
public void SetExchangeRate(IKey userKey, string sourceUniqueCode, string targetUniqueCode, DateTime validFrom, double rate) { Ensure.NotNullOrEmpty(sourceUniqueCode, "sourceUniqueCode"); Ensure.NotNullOrEmpty(targetUniqueCode, "targetUniqueCode"); EnsureExists(userKey, sourceUniqueCode); EnsureExists(userKey, targetUniqueCode); Ensure.Positive(rate, "rate"); UserModel userModel = GetUserModel(userKey); CurrencyExchangeRateSet payload = new CurrencyExchangeRateSet(sourceUniqueCode, targetUniqueCode, validFrom, rate) { UserKey = userKey }; if (userModel.ExchangeRateHashCodes.Contains(payload.GetHashCode())) { throw new CurrencyExchangeRateAlreadyExistsException(); } Publish(payload); }
Task IEventHandler <CurrencyExchangeRateSet> .HandleAsync(CurrencyExchangeRateSet payload) => RaiseEvent(payload);