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_DETAIL object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="aMOUNT">Initial value of the AMOUNT property.</param> /// <param name="dISH_ID">Initial value of the DISH_ID property.</param> /// <param name="bILL_ID">Initial value of the BILL_ID property.</param> public static BILLING_DETAIL CreateBILLING_DETAIL(global::System.Guid id, global::System.Int32 aMOUNT, global::System.Guid dISH_ID, global::System.Guid bILL_ID) { BILLING_DETAIL bILLING_DETAIL = new BILLING_DETAIL(); bILLING_DETAIL.Id = id; bILLING_DETAIL.AMOUNT = aMOUNT; bILLING_DETAIL.DISH_ID = dISH_ID; bILLING_DETAIL.BILL_ID = bILL_ID; return bILLING_DETAIL; }
/// <summary> /// Deprecated Method for adding a new object to the BILLING_DETAIL EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToBILLING_DETAIL(BILLING_DETAIL bILLING_DETAIL) { base.AddObject("BILLING_DETAIL", bILLING_DETAIL); }