public HttpResponseMessage Delete(string id) { try { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Delete(id).ToString())); } catch (Exception e) { ExceptionHandler.Log(e); return(Request.CreateResponse <string>(HttpStatusCode.OK, "")); } }
public HttpResponseMessage Delete(string id) { SqlTransaction tran = DataProvider.beginTrans(); try { string message = id; FinReceiptDT receiptDT = new FinReceiptDT(); DataTable dtReceipt = receiptDT.GetByCond("InvoiceId=" + id); if (dtReceipt.Rows.Count > 0) { message = "Lỗi: Phiếu bán hàng đã thu tiền, không thể xóa."; } else { DataTable dtInvoice = invoiceDT.GetByID(id); DataTable invoiceDetail = invoiceDetailDT.GetByCond("InvoiceId=" + id); foreach (DataRow row in invoiceDetail.Rows) { string invCode = dtInvoice.Rows[0]["Code"].ToString(); int storeId = Converter.ToInt32(dtInvoice.Rows[0]["StoreId"]); int productId = Converter.ToInt32(row["ProductId"]); string quantity = row["ProductId"].ToString(); StoreModel.ChangeInvoice(invCode, storeId, productId, quantity, tran); invoiceDetailDT.DeleteViaCond("InvoiceId=" + id, tran); invoiceDT.Delete(id, tran); tran.Commit(); } } return(Request.CreateResponse <string>(HttpStatusCode.OK, message)); } catch (Exception e) { ExceptionHandler.Log(e); tran.Rollback(); return(Request.CreateResponse <string>(HttpStatusCode.OK, "")); } finally { tran.Dispose(); } }