Beispiel #1
0
        private object GetInforOrder(int userID)
        {
            var    dao          = new OrdersDetailsDAO();
            object orderbookLst = dao.GetOrder(userID);

            return(orderbookLst);
        }
Beispiel #2
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"));
        }
Beispiel #3
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"));
            }
        }