public void Setup() { configurationAccessor = Options.Create <Configuration>(new Configuration() { Currencies = new System.Collections.Generic.List <CurrencySetting>() { new CurrencySetting { ISO = "USD", ApiUrl = "http://www.bancoprovincia.com.ar/Principal/Dolar", FakeValue = 1, MaxSupported = 200 }, new CurrencySetting { ISO = "BRL", ApiUrl = "", FakeValue = 1, MaxSupported = 300 } } }); var options = new DbContextOptionsBuilder <CurrencyDBContext>().UseInMemoryDatabase("ServiceTest").Options; currencyDBContext = new CurrencyDBContext(options); currencyRepository = new CurrencyRepository(currencyDBContext); rateTransactionRepository = new RateTransactionRepository(currencyDBContext); unitOfWork = new UnitOfWork(currencyDBContext, currencyRepository, rateTransactionRepository); currencyRate = new CurrencyRate(); request = new Request(); defaulController = new DefaultController(configurationAccessor, request, currencyRate, unitOfWork); }
public DefaultController( IOptions <Configuration> accessor, IRequest request, ICurrencyRate currencyRate, IUnitOfWork unitOfWork) : base(accessor, unitOfWork) { _request = request; _currencyRate = currencyRate; }
private void ManageSourceCurrency <T>(T itemModel, IInvoiceForm form) where T : InvoiceFormModelBase { ICurrency sourceCurrency = null; ICurrencyRate rateInfo = null; foreach (var item in form.Items) { if (sourceCurrency == null) { sourceCurrency = item.SourceCurrency; } if ((sourceCurrency?.Id ?? -1) != (item.SourceCurrencyId ?? -1)) { throw new InvalidOperationException($"Faktura {form.InvoiceNumber} má položky v různých měnách, nelze zpracovat"); } if (rateInfo == null) { rateInfo = item.Conversion?.CurrencyRate; } if ((rateInfo?.Id ?? -1) != (item.Conversion?.CurrencyRate?.Id ?? -1)) { throw new InvalidOperationException($"Faktura {form.InvoiceNumber} má položky v cizí měně, které byly převedeny za použití různých měnových kurzů, nelze zpracovat"); } } if (sourceCurrency == null) { return; } if (rateInfo == null) { throw new InvalidOperationException($"Pro fakturu {form.InvoiceNumber} chybi informace o prevodnim kurzu, nelze zpracovat"); } var sum = form.Items.Sum(i => i.SourceCurrencyPrice ?? 0); itemModel.OriginalCurrencyPriceValue = sum; itemModel.OriginalCurrencyPrice = StringUtil.FormatDecimal(sum); itemModel.ConversionRateValue = rateInfo.Rate; itemModel.ConversionRate = StringUtil.FormatDecimal(rateInfo.Rate); itemModel.ConversionRateLink = rateInfo.SourceLink; itemModel.OriginalCurrencySymbol = sourceCurrency.Symbol; }
public ICurrencyConversion CreateCurrencyConversion(ICurrencyRate usedRate, decimal sourceValue) { var converted = sourceValue * usedRate.Rate; var conversion = m_database.New <ICurrencyConversion>(c => { c.ConversionDt = DateTime.Now; c.CurrencyRateId = usedRate.Id; c.SourceCurrencyId = usedRate.SourceCurrencyId; c.TargetCurrencyId = usedRate.TargetCurrencyId; c.SourceValue = sourceValue; c.TargetValue = converted; c.ConversionDt = DateTime.Now; c.ProjectId = usedRate.ProjectId; }); m_database.Save(conversion); return(conversion); }
public WalletController(IUserRepository userRepository, ILoggerService logger, ICurrencyRate currencyRateProvider) { this._userRepository = userRepository; this._logger = logger; this._currencyRateProvider = currencyRateProvider; }