Exemple #1
0
        public ActionResult Donation(decimal?amount)
        {
            if (string.IsNullOrEmpty(this.CurrentUser.AccountName) || !amount.HasValue && amount.Value > 0)
            {
                TempData["ErrorMessage"] = "Please enter a valid donation amount.";
                return(RedirectToAction("Dancefloor", "Home"));
            }

            OnionHandler handler = new OnionHandler();

            // seems that rpc getbalance delivers wrong amounts.. Check explorer.deeponion.org instead.
            //decimal amountSpendable = handler.GetAccountBalance(this.CurrentUser.AccountName);
            decimal amountSpendable = OnionPriceChecker.GetAddressBalance(this.CurrentUser.OnionAddress);



            if (amount.Value > amountSpendable)
            {
                TempData["ErrorMessage"] = "Insufficient funds! You cannot donate more than " + amountSpendable + " Onions!";
                return(RedirectToAction("Dancefloor", "Home"));
            }

            try
            {
                if (handler.Move(this.CurrentUser.AccountName, ConfigurationManager.AppSettings["DonationAccountName"].ToString(), amount.Value))
                {
                    TempData["SuccessMessage"] = "We received your donation of " + amount.Value + " Onions. Thank you so much!";
                }
                else
                {
                    TempData["ErrorMessage"] = "Ooops, something went wrong. Thanks for the good intentions.";
                }
            }
            catch (Exception ex)
            {
                Logger.Error("OnionController->Donation: " + ex.Message);
                TempData["ErrorMessage"] = "Ooops, something went wrong. Thanks for the good intentions.";
            }

            return(RedirectToAction("Dancefloor", "Home"));
        }