Beispiel #1
0
        public Price(decimal amount, string currency)
        {
            if (currency != "BTC" && !BitcoinPriceData.GetAllCodes().Any(s => s.ToUpper() == currency.ToUpper()))
            {
                throw new Exception("Unsupported currency");
            }


            PegCurrency = currency.ToUpper();
            Value       = amount;

            if (PegCurrency == "BTC")
            {
                BTC = amount;
                USD = BitcoinPriceData.ToFiat(amount, "USD");
            }
            else if (PegCurrency == "USD")
            {
                BTC = BitcoinPriceData.ToBTC(amount, "USD");
                USD = amount;
            }
            else
            {
                BTC = BitcoinPriceData.ToBTC(amount, PegCurrency);
                USD = BitcoinPriceData.ToFiat(BTC, "USD");
            }
        }
        public void InsertListing(NewListingModel listing)
        {
            decimal btcprice = listing.PegCurrency == "BTC" ? listing.Price : BitcoinPriceData.ToBTC(listing.Price, listing.PegCurrency);

            db.Listings.Add(new Listing()
            {
                ListingId   = Guid.NewGuid(),
                CatId       = (short)listing.Category.Value,
                CreateDate  = DateTime.Now,
                Description = listing.Description,
                ExpireDate  = DateTime.Now.AddDays(30),
                IsApproved  = false,
                PegCurrency = listing.PegCurrency,
                PriceBTC    = btcprice,
                PriceUSD    = BitcoinPriceData.ToFiat(btcprice, "USD"),
                Title       = listing.Title,
                UserId      = listing.UserId
            });
        }