public ActionResult Create(PaymentInfo paymentinfo)
        {
            if (ModelState.IsValid)
            {
                paymentinfo.PaymentInfoID = Guid.NewGuid();
                db.PaymentInfoes.Add(paymentinfo);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.OrderID = new SelectList(db.Orders, "OrderID", "OrderID", paymentinfo.OrderID);
            return View(paymentinfo);
        }
        public ActionResult PayNow(PayNow payNow)
        {
            try
            {
                string transactionId = "";
                BraintreeGateway gateway = new BraintreeGateway(Braintree.Environment.SANDBOX, "yfdwsyrvnk3szzvx", "n6n49xttqyjyfqtt", "e3bdf8c24b739625011a335a2b382ab3");
                payNow.Amount = Convert.ToDecimal(Session["GrandTotal"]);
                var request = new TransactionRequest
                {
                    Amount = payNow.Amount,
                    CreditCard = new TransactionCreditCardRequest
                    {
                        Number = payNow.CardNumber,
                        ExpirationDate = payNow.ExpMonth + "/" + payNow.ExpYear,
                        CVV = payNow.CVV
                    }
                };

                Result<Transaction> result = gateway.Transaction.Sale(request);
                transactionId = result.Target.Id;

                var list = Session["AddtoCartItems"] as List<AddtoCart>;

                string Email = Session["UserName"].ToString();
                Guid userId = db.Users.Where(u => u.EmailID == Email).Single().UsersID;

                //  generate Order
                Order order = new Order();
                decimal? TaxAmount = Convert.ToDecimal(Session["TaxAmount"].ToString());
                decimal? TotalAmount = Convert.ToDecimal(Session["GrandTotal"].ToString());

                order.OrderID = Guid.NewGuid();
                order.UsersID = userId;
                order.OrderDate = DateTime.Now;
                order.TaxAmount = TaxAmount;
                order.TotalAmount = TotalAmount;
                order.CreateDate = DateTime.Now;
                order.ModifiedDate = DateTime.Now;

                db.Orders.Add(order);
                db.SaveChanges();

                //  generate Order Details
                foreach (var product in list)
                {
                    if (product != null)
                    {
                        OrderDetail orderDetail = new OrderDetail();

                        orderDetail.OrderDetailID = Guid.NewGuid();
                        orderDetail.OrderID = order.OrderID;
                        orderDetail.ProductID = product.ProductId;
                        orderDetail.Qty = product.Qty;

                        orderDetail.Price = product.Price;
                        orderDetail.Size = product.Size;
                        orderDetail.CreateDate = DateTime.Now;
                        orderDetail.ModifiedDate = DateTime.Now;

                        var product1 = db.Products.Find(product.ProductId);

                        if(product1 != null)
                        {
                            product1.Qty = (product1.Qty - product.Qty);
                            db.Entry(product1).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                        db.OrderDetails.Add(orderDetail);
                        db.SaveChanges();

                        //  update query ProductStock

                    }
                }

                //  generate Payment Info

                PaymentInfo paymentInfo = new PaymentInfo();
                paymentInfo.PaymentInfoID = Guid.NewGuid();
                paymentInfo.TransationID = transactionId;
                paymentInfo.OrderID = order.OrderID;
                paymentInfo.CreateDate = DateTime.Now;
                paymentInfo.ModifiedDate = DateTime.Now;

                db.PaymentInfoes.Add(paymentInfo);
                db.SaveChanges();

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return RedirectToAction("ShippingAddress");

            //return RedirectToAction("Success");
        }
 public ActionResult Edit(PaymentInfo paymentinfo)
 {
     if (ModelState.IsValid)
     {
         db.Entry(paymentinfo).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.OrderID = new SelectList(db.Orders, "OrderID", "OrderID", paymentinfo.OrderID);
     return View(paymentinfo);
 }