Example #1
0
        public async Task <List <ExchageRateDto> > GetBtcEthValue()
        {
            //temp need remove
            var usdCurrency = await _currenciesRepository.FirstOrDefaultAsync(c => c.Code.Equals("USD"));

            var supportedCurrency = await _supportedCurrencyRepository.FirstOrDefaultAsync(c => c.CurrencyId.Equals(usdCurrency.Id));

            if (supportedCurrency == null)
            {
                supportedCurrency = new SupportedCurrency
                {
                    CreationTime = DateTime.Now.ToUniversalTime(),
                    CurrencyId   = usdCurrency.Id,
                    TenantId     = AbpSession.TenantId,
                };

                await _supportedCurrencyRepository.InsertAsync(supportedCurrency);

                var exchangeRate = await _exchangeRateRepository.FirstOrDefaultAsync(er => er.CurrencyId.Equals(supportedCurrency.CurrencyId));

                if (exchangeRate == null)
                {
                    exchangeRate = new ExchangeRate {
                        CurrencyId = usdCurrency.Id
                    };
                    exchangeRate.CreationTime      = DateTime.Now.ToUniversalTime();
                    exchangeRate.Price             = 0.25M;
                    exchangeRate.IsAutomaticUpdate = true;
                    exchangeRate.UpdatedBy         = null;

                    await _exchangeRateRepository.InsertAndGetIdAsync(exchangeRate);
                }
            }
            ////

            var supportedCurrenciesQueryable = _supportedCurrencyRepository.GetAll();

            var exchangeRatesQueryable = _exchangeRateRepository.GetAll();

            var currenciesQueryable = _currenciesRepository.GetAll();

            var queryable = supportedCurrenciesQueryable.Join(exchangeRatesQueryable, er => er.CurrencyId, sc => sc.CurrencyId, (sc, er) =>
                                                              new { ExchangeRate = er, SupportedCurrency = sc }).Join(currenciesQueryable, o => o.SupportedCurrency.CurrencyId, c => c.Id, (o, c) =>
                                                                                                                      new { ExchangeRate = o.ExchangeRate, Currency = c });

            return(await queryable.Select(o =>
                                          new ExchageRateDto
            {
                Id = o.ExchangeRate.Id,
                Currency = ObjectMapper.Map <CurrencyDto>(o.Currency),
                Price = o.ExchangeRate.Price,
                IsAutoWallet = o.ExchangeRate.IsAutoWallet
            }).ToListAsync());
        }
Example #2
0
        protected override ValidationResult IsValid(object value,
                                                    ValidationContext validationContext)
        {
            var code = (string)value;

            if (!SupportedCurrency.IsCurrencySupported(code))
            {
                return(new ValidationResult(GetErrorMessage(code)));
            }

            return(ValidationResult.Success);
        }