Пример #1
2
        private IList<IPriceValue> GetDiscountPrices(IList<IPriceValue> prices, MarketId marketId, Currency currency)
        {
            currency = GetCurrency(currency, marketId);

            var priceValues = new List<IPriceValue>();
            
            _promotionHelper.Reset();
            
            foreach (var entry in GetEntries(prices))
            {
                var price = prices
                    .OrderBy(x => x.UnitPrice.Amount)
                    .FirstOrDefault(x => x.CatalogKey.CatalogEntryCode.Equals(entry.Code) &&
                        x.UnitPrice.Currency.Equals(currency));
                if (price == null)
                {
                    continue;
                }

                priceValues.Add(_promotionEntryService.GetDiscountPrice(
                    price, entry, currency, _promotionHelper));
                
            }
            return priceValues;
        }
        // So the same parser can be used for It and Fr variations
        public OnGameFastParserImpl(SiteName siteName = SiteName.OnGame)
        {
            _siteName = siteName;

            _numberFormatInfo = new NumberFormatInfo
            {
                NegativeSign = "-",
                CurrencyDecimalSeparator = ".",
                CurrencyGroupSeparator = ",",
            };

            switch (siteName)
            {
                case SiteName.OnGameIt:
                case SiteName.OnGameFr:
                    _numberFormatInfo.CurrencySymbol = "€";
                    _currency = Currency.EURO;
                    break;
                default:
                    _numberFormatInfo.CurrencySymbol = "$";
                    _currency = Currency.USD;
                    break;

            }
        }
Пример #3
0
        /// <summary>Converts the string representation of a money value to its <see cref="Money"/> equivalent.</summary>
        /// <param name="value">The string representation of the number to convert.</param>
        /// <param name="currency">The currency to use for parsing the string representation.</param>
        /// <returns>The equivalent to the money amount contained in <i>value</i>.</returns>
        /// <exception cref="System.ArgumentNullException"><i>value</i> is <b>null</b> or empty.</exception> 
        /// <exception cref="System.FormatException"><i>value</i> is not in the correct format or the currency sign matches with multiple known currencies!</exception>
        /// <exception cref="System.OverflowException"><i>value</i> represents a number less than <see cref="Decimal.MinValue"/> or greater than <see cref="Decimal.MaxValue"/>.</exception>
        public static Money Parse(string value, Currency currency)
        {
            if (string.IsNullOrWhiteSpace(value))
                throw new ArgumentNullException(nameof(value));

            return Parse(value, NumberStyles.Currency, GetNumberFormatInfo(currency, null), currency);
        }
Пример #4
0
 public VolatilitySurfaceData(string definitionName, string specificationName, Currency currency, string interpolatorName)
 {
     _definitionName = definitionName;
     _specificationName = specificationName;
     _currency = currency;
     _interpolatorName = interpolatorName;
 }
Пример #5
0
 public CurrencyRest(Currency currency)
 {
     Id = currency.Id;
     Name = currency.Name;
     Accuracy = currency.Accuracy;
     IsBase = currency.IsBase();
 }
Пример #6
0
        public GenerateRequestMessage(string pxPayUserId,
            string pxPayKey,
            string urlSuccess,
            string urlFail,
            Currency currencyInput,
            TxnType txnType,
            decimal amount = 0,
            ClientType clientType = DpsPayfit.Client.ClientType.Internet,
            DateTimeOffset? timeout = null)
        {
            if (string.IsNullOrWhiteSpace(pxPayUserId)) throw new ArgumentNullException(nameof(pxPayUserId));
            if (string.IsNullOrWhiteSpace(pxPayKey)) throw new ArgumentNullException(nameof(pxPayKey));
            if (string.IsNullOrWhiteSpace(urlSuccess)) throw new ArgumentNullException(nameof(urlSuccess));
            if (string.IsNullOrWhiteSpace(urlFail)) throw new ArgumentNullException(nameof(urlFail));

            PxPayUserId = pxPayUserId;
            PxPayKey = pxPayKey;
            UrlSuccess = urlSuccess;
            UrlFail = urlFail;
            Amount = amount;
            CurrencyInput = currencyInput;
            TxnType = txnType.ToString();
            ClientType = clientType.ToString();
            if (timeout.HasValue)
            {
                Timeout = $"{timeout:yyMMddHHmm}";
            }
        }
Пример #7
0
 // das ist ein Konstruktor. Er hat keinen Rückgabewert
 //private Currency m_currency;
 public Buch(string derTitel, decimal derPreis, Currency currency)
 {
     titel = derTitel;
     SetPreis (derPreis); // Zuweisung des Wertes über Funktion.
     this.currency=currency; // This ist Referenz auf Objekt selbst und somit auf die private Variable!
     //m_currency=currency;
 }
Пример #8
0
        public IPriceValue GetDiscountPrice(IPriceValue price, EntryContentBase entry, Currency currency, PromotionHelperFacade promotionHelper)
        {
            var promotionEntry = CreatePromotionEntry(entry, price);
            var filter = new PromotionFilter
            {
                IgnoreConditions = false,
                IgnorePolicy = false,
                IgnoreSegments = false,
                IncludeCoupons = false
            };

            var sourceSet = new PromotionEntriesSet();
            sourceSet.Entries.Add(promotionEntry);
            var promotionContext = promotionHelper.Evaluate(filter, sourceSet, sourceSet, false);

            if (promotionContext.PromotionResult.PromotionRecords.Count > 0)
            {
                return new PriceValue
                {
                    CatalogKey = price.CatalogKey,
                    CustomerPricing = CustomerPricing.AllCustomers,
                    MarketId = price.MarketId,
                    MinQuantity = 1,
                    UnitPrice = new Money(price.UnitPrice.Amount - GetDiscountPrice(promotionContext), currency),
                    ValidFrom = DateTime.UtcNow,
                    ValidUntil = null
                };
            }
            return price;
        }
Пример #9
0
 public ForexRate(Currency currency, double rate, int day)
     : this()
 {
     Currency = currency;
     Rate = rate;
     Day = day;
 }
Пример #10
0
        protected override void OnLoadFromConfig(ConfigNode node)
        {
            base.OnLoadFromConfig(node);

            currency = ConfigNodeUtil.ParseValue<Currency>(node, "currency");
            advance = ConfigNodeUtil.ParseValue<double>(node, "advance");
        }
 /// <summary>
 /// Represents a money.
 /// </summary>
 /// <param name="value">Value for the money.</param>
 public MoneyForExercise2(decimal value, Currency currency)
 {
     this.value = value;
     this.MinValue = 6;
     //
     this.currency = currency;
 }
Пример #12
0
        public HttpResponseMessage update(Currency post)
        {
            // Check for errors
            if (post == null)
            {
                return Request.CreateResponse<string>(HttpStatusCode.BadRequest, "The post is null");
            }

            // Make sure that the data is valid
            post.currency_code = AnnytabDataValidation.TruncateString(post.currency_code, 3);
            post.conversion_rate = AnnytabDataValidation.TruncateDecimal(post.conversion_rate, 0, 9999.999999M);

            // Get the saved post
            Currency savedPost = Currency.GetOneById(post.currency_code);

            // Check if the post exists
            if (savedPost == null)
            {
                return Request.CreateResponse<string>(HttpStatusCode.BadRequest, "The record does not exist");
            }

            // Update the post
            Currency.Update(post);

            // Return the success response
            return Request.CreateResponse<string>(HttpStatusCode.OK, "The update was successful");

        } // End of the update method
Пример #13
0
        public HttpResponseMessage add(Currency post)
        {
            // Check for errors
            if (post == null)
            {
                return Request.CreateResponse<string>(HttpStatusCode.BadRequest, "The post is null");
            }

            // Make sure that the data is valid
            post.currency_code = AnnytabDataValidation.TruncateString(post.currency_code, 3);
            post.conversion_rate = AnnytabDataValidation.TruncateDecimal(post.conversion_rate, 0, 9999.999999M);

            // Check if the currency exists
            if(Currency.MasterPostExists(post.currency_code) == true)
            {
                return Request.CreateResponse<string>(HttpStatusCode.BadRequest, "The currency already exists");
            }

            // Add the post
            Currency.Add(post);

            // Return the success response
            return Request.CreateResponse<string>(HttpStatusCode.OK, "The post has been added");

        } // End of the add method
 protected override void OnLoadFromConfig(ConfigNode node)
 {
     currency = ConfigNodeUtil.ParseValue<Currency>(node, "currency");
     effectDescription = ConfigNodeUtil.ParseValue<string>(node, "effectDescription");
     affectReasons = ConfigNodeUtil.ParseValue<List<TransactionReasons>>(node, "affectReason");
     multipliers = ConfigNodeUtil.ParseValue<List<float>>(node, "multiplier");
 }
Пример #15
0
        public void CompareToTest()
        {
            Currency currency = new Currency("USD", "USD");
            Money target = new Money(100, currency);
            Money other = null;
            int actual;

            try
            {
                actual = target.CompareTo(other);
                Assert.Fail("Expected ArgumentNullException");
            }
            catch (ArgumentNullException) { }

            target = new Money(100, currency);
            other = new Money(100, currency);
            actual = target.CompareTo(other);
            Assert.AreEqual<int>(0, actual);

            target = new Money(50, currency);
            other = new Money(100, currency);
            actual = target.CompareTo(other);
            Assert.AreEqual<int>(-1, actual);

            target = new Money(50, currency);
            other = new Money(20, currency);
            actual = target.CompareTo(other);
            Assert.AreEqual<int>(1, actual);
        }
Пример #16
0
        public static void UpdateCurrency(Currency currency)
        {
            if (currency.IsBase == 1)
            {
                UpdateIsBaseCurrency();
            }
            using (var hdc = new HotelDataEntryDataContext())
            {
                var cur = hdc.Currencies.Single(item => item.CurrencyId == currency.CurrencyId);
                cur.CurrencyName = currency.CurrencyName;
                cur.CurrencyCode = currency.CurrencyCode;
                cur.Status = currency.Status;
                cur.ConversionRate = currency.ConversionRate;
                cur.UpdateDateTime = DateTime.Now;
                cur.IsBase = currency.IsBase;

                try
                {
                    hdc.SubmitChanges();
                }
                catch (SqlException ex)
                {
                    if (ex.Number == 2601 || ex.Number == 2627)
                    {
                        throw;
                    }
                }
            }
        }
 public DomainCreditPaymentPlanItem(double mainSum, double percentSum, Currency currency, DateTime startDate)
 {
     MainSum = mainSum;
     PercentSum = percentSum;
     Currency = currency;
     StartDate = startDate;
 }
Пример #18
0
 public CurrencyInfo GetCurrencyInfo(Currency currency)
 {
     CurrencyInfoResponse currencyInfoResponse = restClient.GetResponse<CurrencyInfoResponse>(String.Format("BTC{0}/money/currency", currency.ToString()), Method.POST, null, AccessType.Public);
     if(currencyInfoResponse.CurrencyInfo == null)
         throw new Exception("Failed to deserialize JSON object of type " + typeof(CurrencyInfo) + ". " + MtGoxRestClient.lastResponse);
     return currencyInfoResponse.CurrencyInfo;
 }
Пример #19
0
 public Depth GetDepth(Currency currency)
 {
     DepthResponse depthResponse = restClient.GetResponse<DepthResponse>(String.Format("BTC{0}/money/depth/fetch", currency.ToString()), Method.GET, null, AccessType.Public);
     if (depthResponse.Depth == null)
         throw new Exception("Failed to deserialize JSON object of type " + typeof(Depth) + ". " + MtGoxRestClient.lastResponse);
     return depthResponse.Depth;
 }
Пример #20
0
 public DogeLabel(double pamount, string plabel, string pfulllabel,Currency pcurrency)
 {
     amount = pamount;
     label = plabel;
     fulllabel = pfulllabel;
     currency = pcurrency;
 }
 public async Task<ActionResult> GetBestDeal(DateTime startDate, DateTime endDate, Currency baseCurrency, decimal amount)
 {
     try
     {
         var allCurrencies = CommonUtils.EnumUtil.GetValues<Currency>();
         var calcullatorCurrencies = allCurrencies.Where(c => c != baseCurrency).ToArray();
         var calculatorResult = await _ratesCalculator.CalculateBestDealAsync(startDate, endDate, baseCurrency, calcullatorCurrencies, amount);
         var result = new
         {
             CalculationParameters = new
             {
                 StartDate = startDate,
                 EndDate = endDate,
                 BaseCurrency = baseCurrency,
                 Amount = amount
             },
             CalculationResult = calculatorResult.Item1,
             // need to convert rates dictionary, because standard MVC json serializer can't seriale dictionary where key is enum
             // http://stackoverflow.com/questions/2892910/problems-with-json-serialize-dictionaryenum-int32 
             Rates = calculatorResult.Item2.Select(x => new { x.Date, x.Holiday, Rates = x.Rates.ToJsonDictionary() }) 
         };
         return Json(result, JsonRequestBehavior.AllowGet);
     }
     catch (Exception ex)
     {
         _logger.Error(ex, "Error: failed to CalculateBestDeal.");
         throw;
     }
 }
Пример #22
0
 public myPrice convert(Currency target)
 {
     if (target == Unit)
         return this;
     else
         return new myPrice(Amount * ExchangeRates.Get(Unit, target), target);
 }
Пример #23
0
 public Trasaction(decimal balance, decimal ammount, TransactionType transactionType, Currency currency)
 {
     this.balance = balance;
     this.ammount = ammount;
     this.transactionType = transactionType;
     this.currency = currency;
 }
Пример #24
0
 public void addCurrency(Currency currency, double value)
 {
     if (!this.holder.ContainsKey(currency))
     {
         this.holder.Add(currency, value);
     }
 }
Пример #25
0
        /// <summary>
        /// Gets exchange rate 'from' currency 'to' another currency.
        /// </summary>
        public static decimal Get(Currency from, Currency to)
        {
            // exchange rate is 1:1 for same currency
            if (from == to) return 1;

            // use web service to query current exchange rate
            // request : http://download.finance.yahoo.com/d/quotes.csv?s=EURUSD=X&f=sl1d1t1c1ohgv&e=.csv
            // response: "EURUSD=X",1.0930,"12/29/2015","6:06pm",-0.0043,1.0971,1.0995,1.0899,0
            var key = string.Format("{0}{1}", from, to); // e.g. EURUSD means "How much is 1 EUR in USD?".
            // if we've already downloaded this exchange rate, use the cached value
            if (s_rates.ContainsKey(key)) return s_rates[key];

            // otherwise create the request URL, ...
            var url = string.Format(@"http://download.finance.yahoo.com/d/quotes.csv?s={0}=X&f=sl1d1t1c1ohgv&e=.csv", key);
            // download the response as string
            var data = new WebClient().DownloadString(url);
            // split the string at ','
            var parts = data.Split(',');
            // convert the exchange rate part to a decimal
            var rate = decimal.Parse(parts[1], CultureInfo.InvariantCulture);
            // cache the exchange rate
            s_rates[key] = rate;

            // and finally perform the currency conversion
            return rate;
        }
Пример #26
0
        static void Main(string[] args)
        {
            try
            {
                   Currency balance = new Currency(50,35);

                   Console.WriteLine(balance);
                   Console.WriteLine("balance is " + balance);
                   Console.WriteLine("balance is (using ToString()) " + balance.ToString());

                   float balance2 = balance;

                   Console.WriteLine("After converting to float, = " + balance2);

                   balance = (Currency)balance2;

                   Console.WriteLine("After converting back to Currency, = " + balance);
                   Console.WriteLine("Now attempt to convert out of range value of " +
                                     "-$50.50 to a Currency:");

                checked
                {
                    balance = (Currency)(-50.50);
                    Console.WriteLine("Result is " + balance.ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception occurred: " + e.Message);
            }

            Console.ReadLine();
        }
Пример #27
0
        public string FormatCurrency(decimal amount, Currency targetCurrency, bool includeSymbol = true)
        {
            //find out the culture for the target currency
            var culture = CultureInfo.GetCultures(CultureTypes.SpecificCultures).FirstOrDefault(c =>
            {
                var r = new RegionInfo(c.LCID);
                return string.Equals(r.ISOCurrencySymbol, targetCurrency.CurrencyCode, StringComparison.CurrentCultureIgnoreCase);
            });

            //the format of display
            var format = targetCurrency.DisplayFormat;
            var locale = targetCurrency.DisplayLocale;

            if (culture == null)
            {
                if (!string.IsNullOrEmpty(locale))
                {
                    culture = new CultureInfo(locale);
                }
            }

            if (string.IsNullOrEmpty(format))
            {
                format = culture == null || !includeSymbol ? "{0:N}" : "{0:C}";
            }

            return culture == null ? string.Format(format, amount): string.Format(culture, format, amount);
        }
Пример #28
0
 public MarkupRate(DateTime from, DateTime to, Currency currency, decimal percentageRate)
 {
     From = from;
     To = to;
     Currency = currency;
     PercentageRate = percentageRate;
 }
Пример #29
0
        public static void AddCurrency(Currency currency)
        {
            if (currency.IsBase == 1)
            {
                UpdateIsBaseCurrency();
            }
            using (var hdc = new HotelDataEntryDataContext())
            {
                hdc.Currencies.InsertOnSubmit(new HotelDataEntryLib.Currency
                                                  {
                                                      CurrencyCode = currency.CurrencyCode,
                                                      CurrencyName = currency.CurrencyName,
                                                      UpdateDateTime = DateTime.Now,
                                                      Status = currency.Status,
                                                      ConversionRate = currency.ConversionRate,
                                                      IsBase = currency.IsBase
                                                  });

                try
                {
                    hdc.SubmitChanges();
                }
                catch (SqlException ex)
                {
                    if (ex.Number == 2601 || ex.Number == 2627)
                    {
                        throw;
                    }
                }
            }
        }
Пример #30
0
 public static Decimal FromOACurrency(long cy)
 {
     return(Currency.ToDecimal(Currency.FromOACurrency(cy)));
 }
Пример #31
0
 // Constructs a Decimal from a Currency value.
 //
 internal Decimal(Currency value)
 {
     this = Currency.ToDecimal(value);
 }
Пример #32
0
 private static extern void FCallToCurrency(ref Currency result, Decimal d);
Пример #33
-1
        public static bool EditCredit(Credit creditToEdit, double? amount, Currency? currency, double? rate, int? months)
        {
            BankContext bank = new BankContext();
            if (!bank.Credits.Contains(creditToEdit))
                return false;
            else
            {
                try
                {
                    if (amount != null)
                        creditToEdit.Amount = (double)amount;
                    if (currency != null)
                        creditToEdit.Currency = (Currency)currency;
                    if (months != null)
                        creditToEdit.Months= (int)months;
                    if (rate != null)
                        creditToEdit.Rate = (double)rate;
                    bank.SaveChanges();
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }

            }
        }