Exemple #1
0
        public ActionResult CancelOrder(int Id, string returnUrl)
        {
            OrdersBook ordersBook = _db.OrdersBooks.Find(Id);

            ordersBook.Canceled         = true;
            ordersBook.Status           = 0;
            _db.Entry(ordersBook).State = System.Data.Entity.EntityState.Modified;
            _db.SaveChanges();
            return(Redirect(returnUrl));
        }
 public bool Insert(OrdersBook order)
 {
     try
     {
         db.OrdersBooks.Add(order);
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Exemple #3
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"));
            }
        }
Exemple #4
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"));
            }
        }
        public bool Insert(OrdersBook order)
        {
            try
            {
                string qrInsert = "Insert into OrdersBooks (FoundedDate, UserID, Status, Address, Phone, Email) Values ('" +
                                  order.FoundedDate + "', " + order.UserID + ", " +
                                  order.Status + ", N'" + order.Address + "', '" + order.Phone + "', '" + order.Email + "')";
                db.Database.ExecuteSqlCommand(qrInsert);
                db.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }
        private void AddBookToOrder(int userId, int bookId)
        {
            using (ISession session = NHibernateSessions.OpenSession())
            {
                var activeOrder = session.Query <Orders>().Where(x => x.UserID.Id == userId).Where(x => x.Active == true).FirstOrDefault();


                if (activeOrder != null)
                {
                    using (var transaction = session.BeginTransaction())
                    {
                        var bookOrder = new OrdersBook()
                        {
                            BookID = bookId, OrderID = activeOrder.Id
                        };
                        session.Save(bookOrder);
                        transaction.Commit();
                    }
                }
            }
        }
Exemple #7
0
        public ActionResult Payment(string CustName, string CustPhone, string CustAdd, string CustEmail)
        {
            var orderBook = new OrdersBook();
            int userID    = Convert.ToInt32(Session["userID"]);

            //Lưu vào trong db OrderBook
            orderBook.FoundedDate = DateTime.Now;
            orderBook.UserID      = userID;
            orderBook.Status      = 0; //đơn hàng vừa được đặt sẽ có trạng thái là đang giao
            orderBook.Address     = CustAdd;
            orderBook.Phone       = CustPhone;
            orderBook.Email       = CustEmail;

            var id     = new OrderBookDAO().Insert(orderBook);
            int tempID = new OrderBookDAO().GetID();

            try
            {
                var cart      = (List <CartItem>)Session[CommonConstant.cartSession];
                var detailDAO = new OrdersDetailsDAO();
                foreach (var item in cart)
                {
                    var orderDetail = new OrdersDetail();
                    orderDetail.OrderID     = tempID;
                    orderDetail.BookID      = item.Books.BookID;
                    orderDetail.Total       = (item.Quantity * item.Books.Price);
                    orderDetail.Quantity    = item.Quantity;
                    orderDetail.CreatedDate = DateTime.Now;
                    orderDetail.Status      = 1;
                    detailDAO.Insert(orderDetail);
                }
                Session[CommonConstant.cartSession] = null;
            }
            catch (Exception ex)
            {
                throw;
            }
            return(Redirect("/hoan-thanh"));
        }
Exemple #8
0
        public ActionResult Payment(string CustName, string CustPhone, string CustAdd, string CustEmail, bool?thanhtoantructuyenNL, bool?thanhtoantructuyenPP)
        {
            if (Session["userName"] == null)
            {
                return(RedirectToAction("LoginUsernormal", "LoginUser"));
            }
            var orderBook = new OrdersBook();
            int userID    = Convert.ToInt32(Session["userID"]);

            //Lưu vào trong db OrderBook
            orderBook.FoundedDate = DateTime.Now;
            orderBook.UserID      = userID;
            orderBook.Status      = 0;
            orderBook.Address     = CustAdd;
            orderBook.Phone       = CustPhone;
            orderBook.Email       = CustEmail;
            orderBook.FullName    = CustName;
            orderBook.Paid        = false; // Mặc định là chưa thanh toán
            bool result = new OrderBookDAO().Insert(orderBook);

            try
            {
                if (result)
                {
                    int tempID = orderBook.OrderID;

                    var    cart      = (List <CartItem>)Session[CommonConstant.cartSession];
                    var    detailDAO = new OrdersDetailsDAO();
                    double sum       = 0;
                    foreach (var item in cart)
                    {
                        var orderDetail = new OrdersDetail();
                        orderDetail.OrderID  = tempID;
                        orderDetail.BookID   = item.Books.BookID;
                        orderDetail.Total    = (item.Quantity * item.Books.Price);
                        orderDetail.Quantity = item.Quantity;
                        orderDetail.Status   = 0;
                        detailDAO.Insert(orderDetail);

                        sum += (item.Books.Price.GetValueOrDefault(0) * item.Quantity);
                    }

                    //Gửi mail thông báo đơn hàng cho Khách hàng
                    string content = System.IO.File.ReadAllText(Server.MapPath("~/Areas/Store/Views/template/newOrder.cshtml"));
                    content = content.Replace("{{CustomerName}}", CustName);
                    content = content.Replace("{{Phone}}", CustPhone);
                    content = content.Replace("{{Email}}", CustEmail);
                    content = content.Replace("{{Address}}", CustAdd);
                    content = content.Replace("{{Total}}", sum.ToString("N0"));
                    new MailHelper().SendMail(CustEmail, "Đơn hàng mới từ QT BookStore", content, "Thông báo Đơn Đặt hàng từ QT BookStore");

                    if ((thanhtoantructuyenNL == null || thanhtoantructuyenNL == false) && (thanhtoantructuyenPP == null || thanhtoantructuyenPP == false))
                    {
                        Session[CommonConstant.cartSession] = null;
                        return(Redirect("/hoan-thanh"));
                    }
                    else if (thanhtoantructuyenPP != null || thanhtoantructuyenPP == true)
                    {
                        var model = new CommonConstant.InforPaypal
                        {
                            OrderId = tempID,
                            Total   = cart.Sum(m => m.Quantity * m.Books.Price) ?? 0
                        };
                        TempData["InforPaypal"] = model;
                        return(RedirectToAction("PaymentWithPaypal", "Paypal"));
                    }
                    else
                    {
                        NL_Checkout nganluong    = new NL_Checkout();
                        double      total        = cart.Sum(m => m.Quantity * m.Books.Price) ?? 0;
                        string      urlThanhToan = nganluong.buildCheckoutUrlNew(Url.Action("PaymentConfirmed", "OrderBook", null, Request.Url.Scheme), ConfigurationManager.AppSettings["email_nganluong"].ToString(), "Thanh toán " + total.ToString("#,##0").Replace(',', '.') + " đồng", tempID.ToString(), total.ToString(), "vnd", 1, 0, 0, 0, 0, "Thanh toán " + total.ToString("#,##0").Replace(',', '.') + " đồng",
                                                                                 "Thanh toán " + total.ToString("#,##0").Replace(',', '.') + " đồng", "");
                        return(Redirect(urlThanhToan));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Không thể thêm đơn hàng vì xảy ra lỗi ở server!");
                    return(View("ThongBaoLoi"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View("ThongBaoLoi"));
            }
        }
    // Use this for initialization
    void Start()
    {
        thisPlayerProps = gameObject.GetComponent <Player> ();

        orderBook = GameObject.FindGameObjectWithTag("GO_OrdersBook").GetComponent <OrdersBook> ();
    }
Exemple #10
0
//	public BasePlayer playerInLead;

    // Use this for initialization
    void Start()
    {
        book = GameObject.FindGameObjectWithTag("GO_OrdersBook").GetComponent <OrdersBook> ();
    }
 // Use this for initialization
 void Start()
 {
     gameManager = GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager> ();
     orderBook   = GameObject.FindGameObjectWithTag("GO_OrdersBook").GetComponent <OrdersBook> ();
 }