public JsonResult CreateBill(string Customer_Phone) { Dictionary <int, Item> order = (Dictionary <int, Item>)Session["order"]; double sum = 0; foreach (var item in order) { sum += item.Value.product.price * item.Value.quantity; } if (sum != 0) { OrderAction.Create_Order(DateTime.Now.Date, (string)Session["id"], sum); int ID_Order = OrderAction.Find(); foreach (var item in order) { BillAction.Create_Bill(ID_Order, item.Value.product.id, item.Value.quantity, item.Value.product.price); } if (!Customer_Phone.Equals("0") || Customer_Phone != "") { MemberShipAction.Increate_Score(Customer_Phone, order.Count * 2); } Session["order"] = null; order.Clear(); ID_Order = 0; sum = 0; return(Json("Good", JsonRequestBehavior.AllowGet)); } else { Session["order"] = null; order.Clear(); sum = 0; return(Json("Bad", JsonRequestBehavior.AllowGet)); } }
/* CREATE BILL AND SAVE DB */ public ActionResult BuyBook() { List <Item> item = new List <Item>(); Dictionary <int, Item> tmp = (Dictionary <int, Item>)Session["cart"]; foreach (var i in tmp.Values) { item.Add(i); } int ID_Customer = int.Parse(Session["id"].ToString()); string Date_Create = DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year; OrderAction.Create_Order(ID_Customer, Date_Create); int id_order = OrderAction.Find_Order(); for (int i = 0; i < item.Count; i++) { BillAction.Create_Bill( id_order, item[i].book.id_sach, item[i].book.ten_sach, item[i].book.tac_gia, item[i].so_luong, item[i].book.gia_ban, item[i].so_luong * item[i].book.gia_ban ); } tmp.Clear(); item.Clear(); Session["Cart"] = null; tmp = null; item = null; return(Redirect("~/Cart/MyOrder")); }