Esempio n. 1
0
        // GET: Store/Order
        public ActionResult Index(string searchString, int page = 1, int pageSize = 5)
        {
            var dao   = new OrderBookDAO();
            var model = dao.ListAllPaging(searchString, page, pageSize);

            ViewBag.SearchString = searchString;
            return(View(model));
        }
Esempio n. 2
0
        public ActionResult ShowOrderByStatusOne(string search_value, int page = 1, int pageSize = 5)
        {
            if (Session["UserName"] == null)
            {
                return(RedirectToAction("Login", "AccountAdmin"));
            }
            var dao   = new OrderBookDAO();
            var model = dao.ListAllPagingFilter(0, search_value, page, pageSize);

            ViewBag.SearchString = search_value;
            return(PartialView("_ShowOrderByStatusOne", model));
        }
Esempio n. 3
0
        // GET: Store/Order
        public ActionResult Index(string searchString, int page = 1, int pageSize = 5)
        {
            if (Session["UserName"] == null)
            {
                return(RedirectToAction("Login", "AccountAdmin"));
            }
            var dao   = new OrderBookDAO();
            var model = dao.ListAllPaging(searchString, page, pageSize);

            ViewBag.SearchString = searchString;
            return(View("~/Areas/Store/Views/Order/Index.cshtml", model));
        }
Esempio n. 4
0
        public ActionResult ShowOrderByStatusOne_Shadow(string search_value, int page = 1, int pageSize = 5)
        {
            if (Session["UserName"] == null)
            {
                return(RedirectToAction("Login", "AccountAdmin"));
            }
            var dao   = new OrderBookDAO();
            var model = dao.ListAllPagingFilter(0, search_value, page, pageSize);

            ViewBag.SearchString = search_value;
            ViewBag.Check        = 1;
            ViewBag.Layout       = "~/Areas/Store/Views/Shared/_Layout.cshtml";
            return(PartialView("_ShowOrderByStatusOne", model));
        }
Esempio n. 5
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"));
            }
        }
Esempio n. 6
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"));
            }
        }
Esempio n. 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"));
        }
Esempio n. 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"));
            }
        }