Ejemplo n.º 1
0
        //[AbpAuthorize(AppPermissions.Pages_Administration)]
        public async Task AddSupportedCurrency(AddSupportCurrencyInput input)
        {
            var currency = _currenciesRepository.FirstOrDefault(input.Id);

            if (currency == null)
            {
                throw new UserFriendlyException(L("CurrencyNotFound"));
            }

            SupportedCurrency supportedCurrency = null;

            supportedCurrency = _supportedCurrenciesRepository.FirstOrDefault(sc => sc.CurrencyId.Equals(currency.Id));

            if (supportedCurrency != null)
            {
                throw new UserFriendlyException(L("SupportedCurrencyAlreadyExist"));
            }

            supportedCurrency = new SupportedCurrency
            {
                CreationTime     = DateTime.Now.ToUniversalTime(),
                CurrencyId       = input.Id,
                WalletId         = input.WalletId,
                WiredInstruction = input.WiredInstruction,
                TenantId         = AbpSession.TenantId,
            };

            await _supportedCurrenciesRepository.InsertAndGetIdAsync(supportedCurrency);

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

            if (exchangeRate == null)
            {
                var exchangeRates = await _exchangeManager.DownloadExchangeRatesAsync();

                await _exchangeManager.UpdateExchangeRatesAsync(exchangeRates);
            }
        }
Ejemplo n.º 2
0
        //[AbpAuthorize(AppPermissions.Pages_Administration)]
        public async Task <PagedResultDto <SupportedCurrencyDto> > GetSupportedCurrencies(GetCurrenciesInput input)
        {
            //temp need remove
            var usdCurrency = await _currenciesRepository.FirstOrDefaultAsync(c => c.Code.Equals("USD"));

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

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

                await _supportedCurrenciesRepository.InsertAsync(supportedCurrency);

                var exchangeRate = await _exchangeRatesRepository.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 _exchangeRatesRepository.InsertAndGetIdAsync(exchangeRate);
                }
            }
            ////

            var currencyType = ParametersToEnum(input.Parameters);

            var supportedCurrenciesQueryable = _supportedCurrenciesRepository.GetAll();

            var currenciesQueryable = _currenciesRepository.GetAll();

            var queryable = supportedCurrenciesQueryable.Join(currenciesQueryable, sc => sc.CurrencyId, c => c.Id, (sc, c) =>
                                                              new { SupportCurrency = sc, Currency = c });

            if (currencyType != CurrencyType.None)
            {
                queryable = queryable.Where(o => o.Currency.IsCrypto == (currencyType == CurrencyType.Crypto));
            }

            queryable = queryable.WhereIf(!input.Filter.IsNullOrWhiteSpace(),
                                          o => o.Currency.Name.Contains(input.Filter) || o.Currency.Code.Contains(input.Filter));

            var currencyShortQueryable = queryable.Select(o =>
                                                          new SupportedCurrencyDto(o.Currency.Id, o.Currency.Name, o.Currency.Code,
                                                                                   o.Currency.ImageUrl, o.SupportCurrency.WalletId, o.SupportCurrency.WiredInstruction, o.SupportCurrency.SortOrder));

            var currenciesCount = await currencyShortQueryable.CountAsync();

            var currencies = await currencyShortQueryable.OrderBy(input.Sorting).PageBy(input).ToListAsync();

            return(new PagedResultDto <SupportedCurrencyDto>(currenciesCount, currencies));
        }