Exemplo n.º 1
0
        public async Task SetCurrencyRateToCacheAsync(CurrencyModel currencyModel, DateTime dateTime)
        {
            var currencySpec = new CurrencySpecification(currencyModel.Abbreviation);
            var from         = (await _currencyRepository.ListAsync(currencySpec)).FirstOrDefault();

            currencySpec = new CurrencySpecification(Byn);
            var to = (await _currencyRepository.ListAsync(currencySpec)).FirstOrDefault();

            if (from == null || to == null)
            {
                return;
            }

            var entity = new CurrencyRate
            {
                Rate   = currencyModel.OfficialRate,
                Date   = dateTime.Date,
                FromId = from.Id,
                ToId   = to.Id
            };
            await _currencyRateRepository.AddAsync(entity);
        }
Exemplo n.º 2
0
        public async Task SetUserDefaultCurrencies(string username, string currencyAbbreviationsText)
        {
            var currencyAbbreviations = currencyAbbreviationsText
                                        .Split(" ")
                                        .Select(x => x.ToUpperInvariant());

            var currenciesSpec = new CurrencySpecification(currencyAbbreviations);
            var currencies     = await _currencyRepository.ListAsync(currenciesSpec);

            var user = await GetUserByUsernameAsync(username);

            var userCurrencyMappingSpecification = new UserCurrencyMappingSpecification(user.Id);
            await _userCurrencyMappingRepository.DeleteAsync(
                await _userCurrencyMappingRepository.ListAsync(userCurrencyMappingSpecification));


            await _userCurrencyMappingRepository.AddAsync(
                currencies.Select(x => new UserCurrencyMapping
            {
                CurrencyId = x.Id,
                UserId     = user.Id
            }));
        }