Example #1
0
        public async Task <GlobalCurrencyRate> GetAsync()
        {
            if (_globalCurrencyRate != null)
            {
                return(_globalCurrencyRate);
            }

            await _semaphore.WaitAsync();

            try
            {
                if (_globalCurrencyRate == null)
                {
                    _globalCurrencyRate = await _globalCurrencyRateRepository.GetAsync();

                    if (_globalCurrencyRate == null)
                    {
                        _globalCurrencyRate = new GlobalCurrencyRate {
                            AmountInTokens = 1, AmountInCurrency = 1
                        }
                    }
                    ;
                }
            }
            finally
            {
                _semaphore.Release();
            }

            return(_globalCurrencyRate);
        }
Example #2
0
        public async Task UpdateAsync(GlobalCurrencyRate globalCurrencyRate)
        {
            await _semaphore.WaitAsync();

            try
            {
                await _globalCurrencyRateRepository.InsertOrUpdateAsync(globalCurrencyRate);

                _globalCurrencyRate = globalCurrencyRate;
            }
            finally
            {
                _semaphore.Release();
            }
        }
Example #3
0
        public async Task InsertOrUpdateAsync(GlobalCurrencyRate globalCurrencyRate)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                var entity = await context.GlobalCurrencyRates.FirstOrDefaultAsync();

                if (entity == null)
                {
                    entity = new GlobalCurrencyRateEntity {
                        Id = Guid.NewGuid()
                    };

                    context.GlobalCurrencyRates.Add(entity);
                }

                _mapper.Map(globalCurrencyRate, entity);

                await context.SaveChangesAsync();
            }
        }