Beispiel #1
0
        /// <summary>
        /// Заполняет данными
        /// </summary>
        public async Task SeedDataAsync()
        {
            var currencies    = _сurrencyRepository.GetCurrencies().Select(c => c.CurrencyId.ToUpper());
            var newCurrencies = _currencies.Distinct()
                                .Where(c => !currencies.Contains(c.CurrencyId.ToUpper()) && !string.IsNullOrEmpty(c.CurrencyId));

            _сurrencyRepository.AddRangeCurrency(newCurrencies);

            await _unitOfWork.SaveChangesAsync();

            currencies = _сurrencyRepository.GetCurrencies().Select(c => c.CurrencyId.ToUpper());
            var currencyPairs    = _сurrencyRepository.GetCurrencyPairs();
            var newCurrencyPairs = _currencyPairs.Distinct()
                                   .Where(cp => currencies.Contains(cp.CurrencyPairToId.ToUpper()) && currencies.Contains(cp.CurrencyPairFromId.ToUpper()) &&
                                          !currencyPairs.Any(c => c.CurrencyPairFromId.ToUpper() == cp.CurrencyPairFromId.ToUpper() && c.CurrencyPairToId.ToUpper() == cp.CurrencyPairToId.ToUpper()));

            _сurrencyRepository.AddRangeCurrencyPairs(newCurrencyPairs);

            await _unitOfWork.SaveChangesAsync();
        }