public bool SendToPayment(Guid order_id) { // Lấy dữ liệu order ORDER order = (from p in Context.ORDER where p.STATUS=="Đang làm" where p.Id == order_id select p).SingleOrDefault(); if (order == null) return false; //Lấy dữ liệu order detail List<ORDER_DETAIL> orderdtl; List<Guid> lstId; orderdtl = (from p in Context.ORDER_DETAIL where p.ORDER_ID == order_id select p).ToList(); if (orderdtl.Count == 0) return false; lstId = (from p in orderdtl select p.Id).ToList(); decimal money = 0; BILLING bill = new BILLING(); bill.Id = Guid.NewGuid(); bill.SELL_DATE = DateTime.Now; bill.TABLE_ID = order.TABLE_ID; bill.STATUS = "Chờ thanh toán"; Context.BILLING.AddObject(bill); for (int i = 0; i < orderdtl.Count; i++) { BILLING_DETAIL billdtl = new BILLING_DETAIL(); billdtl.Id = Guid.NewGuid(); billdtl.DISH_ID = orderdtl[i].DISH_ID; billdtl.AMOUNT = orderdtl[i].AMOUNT; billdtl.CHEF_ID = orderdtl[i].CHEF_ID; billdtl.BILL_ID = bill.Id; money += (orderdtl[i].AMOUNT * orderdtl[i].DISH.PRICE); Context.BILLING_DETAIL.AddObject(billdtl); //Xóa bảng ORDER_DETAIL Context.ORDER_DETAIL.DeleteObject(orderdtl[i]); } bill.MONEY = money; //Xóa bảng ORDER Context.ORDER.DeleteObject(order); //Xóa bảng PROCCESSING List<PROCESSING> lstProccess = (from p in Context.PROCESSING where lstId.Contains(p.ORDERDTL_ID) select p).ToList(); for (int i = 0; i < lstProccess.Count; i++) { Context.PROCESSING.DeleteObject(lstProccess[i]); } Context.SaveChanges(); return true; }
/// <summary> /// Create a new BILLING object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="sELL_DATE">Initial value of the SELL_DATE property.</param> /// <param name="mONEY">Initial value of the MONEY property.</param> /// <param name="tABLE_ID">Initial value of the TABLE_ID property.</param> public static BILLING CreateBILLING(global::System.Guid id, global::System.DateTime sELL_DATE, global::System.Decimal mONEY, global::System.Guid tABLE_ID) { BILLING bILLING = new BILLING(); bILLING.Id = id; bILLING.SELL_DATE = sELL_DATE; bILLING.MONEY = mONEY; bILLING.TABLE_ID = tABLE_ID; return bILLING; }
/// <summary> /// Deprecated Method for adding a new object to the BILLING EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToBILLING(BILLING bILLING) { base.AddObject("BILLING", bILLING); }