Example #1
0
        Task IEventHandler <CurrencyExchangeRateSet> .HandleAsync(CurrencyExchangeRateSet payload)
        {
            UserModel userModel = GetUserModel(payload.UserKey);

            userModel.ExchangeRateHashCodes.Add(payload.GetHashCode());
            return(Task.CompletedTask);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
 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);
         }
     });
 }
Example #5
0
        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();
            }
        }
Example #6
0
        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);
        }
Example #7
0
 Task IEventHandler <CurrencyExchangeRateSet> .HandleAsync(CurrencyExchangeRateSet payload) => RaiseEvent(payload);