Esempio n. 1
0
 public BuySell()
 {
     InitializeComponent();
     vm = new BuySellViewModel();
     button1.Clicked += button1_Clicked;
     BindingContext   = vm;
 }
        public ActionResult Sell(BuySellViewModel model)
        {
            if (Session["player"] == null)
            {
                return(RedirectToAction("Index"));
            }

            Player player = Session["player"] as Player;

            model.Player = player;

            if (!ModelState.IsValid)
            {
                return(View("Sell", model));
            }

            if (player.Inventory[model.PartName] < model.Quantity)
            {
                ModelState.AddModelError("notEnoughParts", "You do not have that many.");
                return(View("Sell", model));
            }

            player.Inventory[model.PartName] -= model.Quantity;
            player.Money     += (player.Prices[model.PartName] * model.Quantity);
            Session["player"] = player;

            return(RedirectToAction("Menu"));
        }
        public ActionResult Buy()
        {
            if (Session["player"] == null)
            {
                return(RedirectToAction("Index"));
            }

            BuySellViewModel viewModel = new BuySellViewModel();

            viewModel.Player = Session["player"] as Player;

            return(View("Buy", viewModel));
        }
Esempio n. 4
0
 public async void HandleConfirmation(BuySellViewModel sender)
 {
     if (vm.SelectedCrypto.PriceUsd != null)
     {
         var config = new ConfirmConfig()
         {
             Title      = "Revendre?",
             Message    = "Voulez vous revendre du " + vm.SelectedCrypto.Name + "qui vaut " + vm.SelectedCrypto.PriceUsd + "$ ?",
             OkText     = "Oui",
             CancelText = "Non",
         };
         if (await UserDialogs.Instance.ConfirmAsync(config))
         {
             vm.DoSomething();
             vm.RefreshData();
         }
     }
 }
        private async System.Threading.Tasks.Task GetJSONAsync(BuySellViewModel buySellViewModel)
        {
            using (var httpClient = new HttpClient())
            {
                JSONResultSnipplet = await httpClient.GetStringAsync("https://api.coindesk.com/v1/bpi/currentprice.json");

                JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
                dynamic JSONFinal = javaScriptSerializer.Deserialize <object>(JSONResultSnipplet);


                var JSONDBData = new JSONBitcoin();

                JSONDBData.Active    = true;
                JSONDBData.Amount    = buySellViewModel.AmountEUR;
                JSONDBData.ChartName = JSONFinal["chartName"];
                JSONDBData.PriceEur  = (float)JSONFinal["bpi"]["EUR"]["rate_float"];
                JSONDBData.Time      = JSONFinal["time"]["updated"];
                JSONDBData.Id        = JSONBitcoinListe.Count() + 1;

                if (buySellViewModel.BuySellAssets == transType.BuyAssets)
                {
                    JSONDBData.Transaction = action.bought;
                }
                else
                {
                    JSONDBData.Transaction = action.sold;
                }

                JSONBitcoinListe.Add(JSONDBData);

                /* "{\"time\":{\"updated\":\"Oct 29, 2020 20:55:00 UTC\",\"updatedISO\":\"2020-10-29T20:55:00+00:00\",\"updateduk\":\"Oct 29, 2020 at 20:55 GMT\"},
                 * \"disclaimer\":\"This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from openexchangerates.org\",
                 * \"chartName\":\"Bitcoin\",
                 * \"bpi\":
                 *          {\"USD\":{\"code\":\"USD\",\"symbol\":\"&#36;\",\"rate\":\"13,473.7222\",\"description\":\"United States Dollar\",\"rate_float\":13473.7222},
                 *           \"GBP\":{\"code\":\"GBP\",\"symbol\":\"&pound;\",\"rate\":\"10,419.0272\",\"description\":\"British Pound Sterling\",\"rate_float\":10419.0272},
                 *           \"EUR\":{\"code\":\"EUR\",\"symbol\":\"&euro;\",\"rate\":\"11,541.2940\",\"description\":\"Euro\",\"rate_float\":11541.294}}}"
                 */
            }
        }
        public async System.Threading.Tasks.Task <ActionResult> BuySell(BuySellViewModel buySellViewModel)
        {
            await GetJSONAsync(buySellViewModel);

            return(RedirectToAction("Index"));
        }
        // GET: JSONBitcoin/Details/5
        public async System.Threading.Tasks.Task <ActionResult> BuySell()
        {
            var obj = new BuySellViewModel();

            return(View(obj));
        }