Ejemplo n.º 1
0
        public async Task <ActionResult> PaypalConfirmed()
        {
            try
            {
                BSDBContext db    = new BSDBContext();
                var         model = (CommonConstant.InforPaypal)TempData["InforOrder"];
                int         Id    = model.OrderId;
                OrdersBook  Order = db.OrdersBooks.Find(Id);
                Order.Paid            = true; // Đã thanh toán
                db.Entry(Order).State = System.Data.Entity.EntityState.Modified;
                await db.SaveChangesAsync();

                var orderBook = new OrderBookDAO().Get(Id);
                historyBankCharging history = new historyBankCharging()
                {
                    email            = orderBook.Email,
                    phone            = orderBook.Phone,
                    fullname         = orderBook.FullName,
                    date_trans       = DateTime.Now,
                    price            = (int)model.Total,
                    order_code       = null,
                    error_text       = null,
                    transaction_info = null,
                    payment_id       = null,
                    payment_type     = "Paypal",
                    secure_code      = null
                };
                db.historyBankChargings.Add(history);
                await db.SaveChangesAsync();

                // giam so luong ton cua cac sách khách đã thanh toán
                foreach (OrdersDetail ordersDetail in Order.OrdersDetails)
                {
                    Book book = db.Books.Find(ordersDetail.BookID);
                    book.TotalQuantity  -= (ordersDetail.Quantity ?? 0); // giảm
                    db.Entry(book).State = System.Data.Entity.EntityState.Modified;
                    await db.SaveChangesAsync();
                }

                Session[CommonConstant.cartSession] = null;
                return(Redirect("/hoan-thanh"));
            }
            catch (Exception ex)
            {
                return(View("ThongBaoLoi"));
            }
        }
Ejemplo n.º 2
0
        // ok roi.
        public async Task <ActionResult> PaymentConfirmed(string transaction_info, string order_code, int price, string payment_id, string payment_type, string error_text, string secure_code)
        {
            BSDBContext db = new BSDBContext();

            if (error_text == "")
            {
                int        Id    = int.Parse(order_code);
                OrdersBook Order = db.OrdersBooks.Find(Id);
                Order.Paid            = true; // Đã thanh toán
                db.Entry(Order).State = System.Data.Entity.EntityState.Modified;
                await db.SaveChangesAsync();

                var orderBook = new OrderBookDAO().Get(Id);
                historyBankCharging history = new historyBankCharging()
                {
                    email            = orderBook.Email,
                    phone            = orderBook.Phone,
                    fullname         = orderBook.FullName,
                    date_trans       = DateTime.Now,
                    price            = price,
                    order_code       = order_code,
                    error_text       = error_text,
                    transaction_info = transaction_info,
                    payment_id       = payment_id,
                    payment_type     = payment_type,
                    secure_code      = secure_code
                };
                db.historyBankChargings.Add(history);
                await db.SaveChangesAsync();

                // giam so luong ton cua cac sách khách đã thanh toán
                foreach (OrdersDetail ordersDetail in Order.OrdersDetails)
                {
                    Book book = db.Books.Find(ordersDetail.BookID);
                    book.TotalQuantity  -= (ordersDetail.Quantity ?? 0); // giảm
                    db.Entry(book).State = System.Data.Entity.EntityState.Modified;
                    await db.SaveChangesAsync();
                }

                Session[CommonConstant.cartSession] = null;
                return(Redirect("/hoan-thanh"));
            }
            else
            {
                return(View("ThongBaoLoi"));
            }
        }