public ActionResult DoneCheckOut(orderFnc bill) { user u = (user)Session["user"]; if (bill != null) { //insert DetailBill Cart gio = (Cart)Session["cart"]; List <CartDetail> cardt; if (gio != null) { try { bill.total_money = gio.getTotalPrice(); bill.date_create = DateTime.Now; bill.users_id = u.id; cardt = gio.getCartDetailList(); if (bill.CreateBill(cardt)) { Session["cart"] = null; return(View()); } } catch (Exception e) { Trace.WriteLine(e.Message); return(RedirectToAction("Index", "Cart")); } } return(RedirectToAction("Index", "Home")); } return(RedirectToAction("CheckOut", "Cart")); }
public ActionResult DoneCheckOut(orderFnc bill) { user userorder = (user)Session["user"]; if (bill != null) { //insert DetailBill Cart gio = (Cart)Session["cart"]; List <CartDetail> cardt; if (gio != null) { try { bill.total_money = gio.getTotalPrice(); cardt = gio.getCartDetailList(); // Nếu thanh toán thành công thì trả về view(); int nextIDOrder = addSV.ID_Return("orders"); if (addSV.Add_order( Session["utoken"] as string, userorder.id, nextIDOrder, bill.total_money.ToString(), DateTime.Now.ToString(), "COD"). Equals("Add success!")) { string message = "Kết quả:"; // Thêm chi tiết hoá đơn foreach (var item in cardt) { message += "\n" + addSV.Add_order_detail( Session["utoken"] as string, userorder.id, nextIDOrder, item.ID, item.Quantity, item.Price ?? 0); } Session["message"] = message; return(View()); // Thanh toán thành công } } catch (Exception e) { Trace.WriteLine(e.Message); return(RedirectToAction("Index", "Cart")); } } return(RedirectToAction("Index", "Home")); // không thanh toán thành công } return(RedirectToAction("CheckOut", "Cart")); }