Exemple #1
0
        public ActionResult CreateTokenTransactions(int amount)
        {
            var LoggedUser = Session["LoggedUser"] as User;

            if (LoggedUser == null)
            {
                return(RedirectToAction("Index"));
            }

            var Prices = new
            {
                Silver   = DB.Settings.Where(s => s.Key == "S").First().Value,
                Gold     = DB.Settings.Where(s => s.Key == "G").First().Value,
                Platinum = DB.Settings.Where(s => s.Key == "P").First().Value,
            };

            // prices in check
            if (amount != Prices.Silver && amount != Prices.Gold && amount != Prices.Platinum)
            {
                return(RedirectToAction("PaymentFailed"));
            }


            // calculate price
            int     currency      = DB.Settings.Find("C").Value;
            int     pricePerToken = DB.Settings.Find("T").Value;
            decimal price         = Currencies.ConvertToRsd(pricePerToken * amount, currency);


            // make submited order
            var NewTokenOrder = DB.TokenOrders.Add(new TokenOrder()
            {
                UserId    = LoggedUser.Id,
                State     = "SUBMITTED",
                Amount    = amount,
                Price     = price,
                CreatedAt = DateTime.Now,
            });

            DB.SaveChanges();

            return(Redirect("http://stage.centili.com/payment/widget?apikey=ce797d8eeab183872300e64cd877a4e3&country=rs&reference=" + NewTokenOrder.Id + "&returnurl=http://matijaiep.azurewebsites.net/User/Confirm")); // &price=" + price);
        }