コード例 #1
0
        public async Task <IActionResult> PaymentConfirm(Payment payment, string code)
        {
            var t = HttpContext.Session.GetInt32("Payment");

            if (t == null)
            {
                RedirectToAction(nameof(Payment));
            }

            if (TransactionHandler.IsValid((int)t, code))
            {
                User   user   = null;
                string userId = HttpContext.Session.GetString("UserId");
                SessionHandler.GetUser(userId, out user);

                try
                {
                    await _context.MakePayment(user, payment);
                }
                catch
                {
                    return(Redirect("/Home/Error"));
                }

                return(RedirectToAction(nameof(PaymentList)));
            }
            else
            {
                ViewBag.ErrMsg = "Wrong confirmation code!";
                return(View(payment));
            }
        }
コード例 #2
0
        public async Task MakePaymentInBank()
        {
            long n     = number++;
            User user2 = new User()
            {
                Name = "Pepa", BirthNumber = 666, Email = "*****@*****.**", Login = "******", Pin = "pepa", Role = 0, AccountNumber = n, CardNumber = number
            };

            _context.Add(user2);
            await _context.SaveChangesAsync();

            double?m1 = user.Money;
            double?m2 = user2.Money;

            pay.DestAccount = n;
            pay.DestBank    = 666;
            await _context.MakePayment(user, pay);

            Assert.IsTrue(user.Money == m1 - pay.Amount);
            Assert.IsTrue(user2.Money == m2 + pay.Amount);

            _context.Remove(user2);
            await _context.SaveChangesAsync();
        }