コード例 #1
0
        public void Transfer(BankAccount account, AccountNumber target, Currency amount)
        {
            BankAccount targetAccount;

            if (_accountNumberToAccount.TryGetValue(target, out targetAccount))
            {
                DateTime         now      = DateTime.Now;
                OutgoingTransfer outgoing = new OutgoingTransfer(
                    account, amount, CurrencyProvider.GetCurrency(0.5m, GetCurrency("USD")),    // NOI18N
                    now, _converter);
                IncommingTransfer incomming = new IncommingTransfer(
                    targetAccount, amount, now, _converter);

                outgoing.Apply();
                incomming.Apply();
            }
            else
            {
                DateTime         now      = DateTime.Now;
                OutgoingTransfer outgoing = new OutgoingTransfer(
                    account, amount, CurrencyProvider.GetCurrency(1m, GetCurrency("USD")),      // NOI18N
                    now, _converter);
                ExternalTransfer external = new ExternalTransfer(target, amount, now);
                outgoing.Apply();
                _interBankTransferSystem.EnqueueTransfer(external);
            }
        }
コード例 #2
0
        /// <summary>
        ///     Format the values of a range facet into a displayable text.
        ///     The base implementation will look into the LocalizationProvider for a Key that match the format:
        ///     If only <paramref name="minValue" /> is defined: {FieldName}_MinValuePattern
        ///     If only <paramref name="maxValue" /> is defined: {FieldName}_MaxValuePattern
        ///     If both <paramref name="minValue" /> and <paramref name="maxValue" /> are defined: {FieldName}_MinMaxValuePattern
        /// </summary>
        /// <param name="fieldName">FieldName of the Facet as returned by the Search Provider</param>
        /// <param name="minValue">Minimum value of the range facet</param>
        /// <param name="maxValue">Maximum value of the range facet</param>
        /// <param name="cultureInfo">Culture</param>
        /// <param name="valueType">Type of the min and max values.</param>
        /// <returns>The localized values if localized; the initial value otherwise</returns>
        public string GetFormattedRangeFacetValues(string fieldName, string minValue, string maxValue, Type valueType, CultureInfo cultureInfo)
        {
            string formatKeyPattern;
            var    formatParams = new ArrayList();

            if (string.IsNullOrWhiteSpace(minValue))
            {
                if (string.IsNullOrWhiteSpace(maxValue))
                {
                    throw new ArgumentException("At least one of the parameters minValue or maxValue must be set");
                }
                formatKeyPattern = SearchConfiguration.FormatRangeFacetMaxValueLocalizationKeyPattern;
                formatParams.Add(Convert.ChangeType(maxValue, valueType));
            }
            else
            {
                formatParams.Add(Convert.ChangeType(minValue, valueType));
                if (string.IsNullOrWhiteSpace(maxValue))
                {
                    formatKeyPattern = SearchConfiguration.FormatRangeFacetMinValueLocalizationKeyPattern;
                }
                else
                {
                    formatKeyPattern = SearchConfiguration.FormatRangeFacetMinMaxValueLocalizationKeyPattern;
                    formatParams.Add(Convert.ChangeType(maxValue, valueType));
                }
            }

            var localizedFormat = LocalizationProvider.GetLocalizedString(new GetLocalizedParam
            {
                Category    = SearchConfiguration.FormatFacetLocalizationCategory,
                Key         = formatKeyPattern.Replace("{FieldName}", fieldName),
                CultureInfo = cultureInfo
            });

            if (localizedFormat != null)
            {
                try
                {
                    var scopeCurrency = CurrencyProvider.GetCurrency();
                    if (!string.IsNullOrEmpty(scopeCurrency))
                    {
                        cultureInfo = LocalizationProvider.GetCultureByCurrencyIso(scopeCurrency);
                        return(string.Format(cultureInfo, localizedFormat, formatParams.ToArray()));
                    }

                    return(string.Format(localizedFormat, formatParams.ToArray()));
                }
                catch (FormatException)
                {
                    // TODO: Log here
                    throw;
                }
            }

            return(string.Format("[{0}]", string.Join(" - ", formatParams.ToArray())));
        }
コード例 #3
0
 private Currency ConvertToMainCurrency(Currency input)
 {
     if (input.CurrencyInfo == _mainCurrency)
     {
         return(input);
     }
     else
     {
         decimal value = input.GetDecimalValue() / (decimal)_ratios[input.CurrencyInfo];
         return(CurrencyProvider.GetCurrency(value, _mainCurrency));
     }
 }
コード例 #4
0
        public void TestUsdConversion()
        {
            CurrencyInfo usd = new CurrencyInfo("USD", "$", "{1}{0}");
            CurrencyInfo eur = new CurrencyInfo("EUR", "€", "{1}{0}");

            CurrencyExchangeConverter converter = new CurrencyExchangeConverter(usd);

            converter.AddRatio(eur, 0.75f);
            Currency currency          = CurrencyProvider.GetCurrency(100, eur);
            Currency convertedCurrency = converter.Convert(currency, usd);

            Currency expectedCurrency = CurrencyProvider.GetCurrency(100 / 0.75m, usd);

            Assert.AreEqual(convertedCurrency.GetDecimalValue(), expectedCurrency.GetDecimalValue());
        }
コード例 #5
0
        public ActionResult Index()
        {
            var currencyCode = CurrencyProfileService.GetCurrencyCode();
            var currency     = currencyProvider.GetCurrency(currencyCode);

            var basket = basketService.GetBasketFor(User).ConvertTo(currency);

            if (basket.Contents.Count == 0)
            {
                return(View("Empty"));
            }
            var vm = new BasketViewModel(basket);

            return(View(vm));
        }
コード例 #6
0
        private Currency ConvertFromMainCurrency(Currency input, CurrencyInfo target)
        {
            if (input == null)
            {
                throw new ArgumentNullException("Input is null, cannot convert");
            }

            if (target == _mainCurrency)
            {
                return(input);
            }
            else
            {
                decimal value = input.GetDecimalValue() * (decimal)_ratios[target];
                return(CurrencyProvider.GetCurrency(value, target));
            }
        }
コード例 #7
0
        public virtual OrderSummaryPaymentViewModel BuildOrderSummaryPaymentViewModel(Overture.ServiceModel.Orders.Payment payment, CultureInfo cultureInfo)
        {
            var methodDisplayNames = LookupService.GetLookupDisplayNamesAsync(new GetLookupDisplayNamesParam
            {
                CultureInfo = cultureInfo,
                LookupType  = LookupType.Order,
                LookupName  = "PaymentMethodType",
            }).Result;

            var paymentMethodDisplayName = methodDisplayNames.FirstOrDefault(x => x.Key == payment.PaymentMethod.Type.ToString()).Value;

            var paymentVm = new OrderSummaryPaymentViewModel
            {
                FirstName         = payment.BillingAddress?.FirstName,
                LastName          = payment.BillingAddress?.LastName,
                PaymentMethodName = paymentMethodDisplayName,
            };

            paymentVm.BillingAddress = CartViewModelFactory.GetAddressViewModel(payment.BillingAddress, cultureInfo);
            paymentVm.Amount         = LocalizationProvider.FormatPrice((decimal)payment.Amount, CurrencyProvider.GetCurrency());

            return(paymentVm);
        }
コード例 #8
0
        public virtual OrderSummaryPaymentViewModel BuildOrderSummaryPaymentViewModel(Overture.ServiceModel.Orders.Payment payment, CultureInfo cultureInfo)
        {
            var creditCartNumber  = string.Empty;
            var expiryDate        = string.Empty;
            var paymentMethodName = string.Empty;

            if (payment.PaymentMethod.PropertyBag != null)
            {
                //TODO : use viewmodelmapper through cartviewmodelfactory ( already exist )
                if (payment.PaymentMethod.Type == PaymentMethodType.SavedCreditCard)
                {
                    if (payment.PaymentMethod.PropertyBag.ContainsKey(SavedCardMask))
                    {
                        creditCartNumber = payment.PaymentMethod.PropertyBag[SavedCardMask].ToString();
                    }

                    if (payment.PaymentMethod.PropertyBag.ContainsKey(SavedExpiryDate))
                    {
                        expiryDate = payment.PaymentMethod.PropertyBag[SavedExpiryDate].ToString();
                    }

                    if (payment.PaymentMethod.PropertyBag.ContainsKey(SavedCardType))
                    {
                        paymentMethodName = payment.PaymentMethod.PropertyBag[SavedCardType].ToString();
                    }
                }
                else
                {
                    if (payment.PaymentMethod.PropertyBag.ContainsKey(CreditCardPaymentProperties.CreditCardNumberLastDigitsKey))
                    {
                        creditCartNumber = payment.PaymentMethod.PropertyBag[CreditCardPaymentProperties.CreditCardNumberLastDigitsKey].ToString();
                    }

                    if (payment.PaymentMethod.PropertyBag.ContainsKey(CreditCardPaymentProperties.CreditCardExpiryDateKey))
                    {
                        expiryDate = payment.PaymentMethod.PropertyBag[CreditCardPaymentProperties.CreditCardExpiryDateKey].ToString();
                    }

                    if (payment.PaymentMethod.PropertyBag.ContainsKey(CreditCardPaymentProperties.CreditCardBrandKey))
                    {
                        paymentMethodName = payment.PaymentMethod.PropertyBag[CreditCardPaymentProperties.CreditCardBrandKey].ToString();
                    }
                }
            }

            bool hasExpired = false;

            if (DateTime.TryParse(expiryDate, out DateTime expirationDate))
            {
                hasExpired = expirationDate < DateTime.UtcNow;
            }

            var paymentVm = new OrderSummaryPaymentViewModel
            {
                FirstName         = payment.BillingAddress.FirstName,
                LastName          = payment.BillingAddress.LastName,
                PaymentMethodName = paymentMethodName,
                CreditCardNumber  = creditCartNumber,
                ExpiryDate        = expiryDate,
                IsExpired         = hasExpired
            };

            paymentVm.BillingAddress = CartViewModelFactory.GetAddressViewModel(payment.BillingAddress, cultureInfo);
            paymentVm.Amount         = LocalizationProvider.FormatPrice(payment.Amount, CurrencyProvider.GetCurrency());

            return(paymentVm);
        }
コード例 #9
0
        public static Bank CreateExampleBank()
        {
            Bank bank = new Bank();

            //parasoft-begin-suppress CS.INTER.ITT
            bank.AddCurrency(new CurrencyInfo("USD", "$", "{1}{0}"));
            bank.AddCurrency(new CurrencyInfo("EUR", "€", "{1}{0}"));
            bank.AddCurrency(new CurrencyInfo("JPY", "¥", "{1}{0}"));
            bank.AddCurrency(new CurrencyInfo("PLN", "zł", "{0} {1}"));
            bank.AddCurrency(new CurrencyInfo("ISK", "kr", "{0} {1}"));

            BankUser user1 = new BankUser("John", "White", "jwhite", "jwhite");
            BankUser user2 = new BankUser("Angela", "Smith", "asmith", "asmith");
            BankUser user3 = new BankUser("Kenta", "Suzuki", "ksuzuki", "ksuzuki");

            bank.AddUser(user1);
            bank.AddUser(user2);
            bank.AddUser(user3);

            bank.AddAccount(new BankAccount(user1, CurrencyProvider.GetCurrency(1323.12m, bank.GetCurrency("USD")), AccountNumber.Create("84534789450005711")));
            bank.AddAccount(new BankAccount(user1, CurrencyProvider.GetCurrency(782.32m, bank.GetCurrency("EUR")), AccountNumber.Create("12534789451800068")));
            bank.AddAccount(new BankAccount(user1, CurrencyProvider.GetCurrency(2182.98m, bank.GetCurrency("JPY")), AccountNumber.Create("67534000458748357")));
            bank.AddAccount(new BankAccount(user1, CurrencyProvider.GetCurrency(82402m, bank.GetCurrency("ISK")), AccountNumber.Create("67534789455487870")));

            bank.AddAccount(new BankAccount(user2, CurrencyProvider.GetCurrency(18681.20m, bank.GetCurrency("EUR")), AccountNumber.Create("32534789459735154")));
            bank.AddAccount(new BankAccount(user3, CurrencyProvider.GetCurrency(5111.71m, bank.GetCurrency("JPY")), AccountNumber.Create("67534789450120008")));

            bank.Coverter = new CurrencyExchangeConverter(bank.GetCurrency("USD"));

            bank.Coverter.AddRatio(bank.GetCurrency("EUR"), 0.775f);
            bank.Coverter.AddRatio(bank.GetCurrency("JPY"), 95.71f);
            bank.Coverter.AddRatio(bank.GetCurrency("ISK"), 125.96f);
            bank.Coverter.AddRatio(bank.GetCurrency("PLN"), 3.243f);

            //Make some transactions

            IList <BankAccount> user1Accounts = bank.GetAccounts(user1);
            IList <BankAccount> user2Accounts = bank.GetAccounts(user2);
            IList <BankAccount> user3Accounts = bank.GetAccounts(user3);

            Currency amount = CurrencyProvider.GetCurrency("1000",
                                                           user1Accounts[0].CurrencyInfo, Thread.CurrentThread.CurrentCulture);

            bank.Transfer(user1Accounts[0], user1Accounts[1].Number, amount);

            amount = CurrencyProvider.GetCurrency("1000",
                                                  user1Accounts[2].CurrencyInfo, Thread.CurrentThread.CurrentCulture);
            bank.Transfer(user1Accounts[2], user2Accounts[0].Number, amount);

            amount = CurrencyProvider.GetCurrency("5000",
                                                  user1Accounts[3].CurrencyInfo, Thread.CurrentThread.CurrentCulture);
            bank.Transfer(user1Accounts[3], user1Accounts[0].Number, amount);

            amount = CurrencyProvider.GetCurrency("50",
                                                  user1Accounts[1].CurrencyInfo, Thread.CurrentThread.CurrentCulture);
            bank.Transfer(user1Accounts[1], user1Accounts[2].Number, amount);

            amount = CurrencyProvider.GetCurrency("250",
                                                  user3Accounts[0].CurrencyInfo, Thread.CurrentThread.CurrentCulture);
            bank.Transfer(user3Accounts[0], user1Accounts[2].Number, amount);

            amount = CurrencyProvider.GetCurrency("350",
                                                  user3Accounts[0].CurrencyInfo, Thread.CurrentThread.CurrentCulture);
            bank.Transfer(user3Accounts[0], user1Accounts[2].Number, amount);

            //parasoft-end-suppress CS.INTER.ITT));
            return(bank);
        }