public void Update(DeliveryNote note) { using (var dmt = DMContext.GetTransaction()) { int noteid = note.noteid; var trans = dmt.BeginTransaction(); DMContext.Delete <DeliveryItem>(p => p.noteid == noteid, trans); DMContext.Update <DeliveryNote>(note, p => p.noteid == noteid, null, trans); if (note.items != null) { foreach (DeliveryItem item in note.items) { item.noteid = note.noteid; DMContext.Insert(item, null, trans); } } trans.Commit(); } }
public bool Add(DeliveryNote note) { bool bRet = false; bool bNewCustomer = false;; int iDeliveryId; CustomerDAC dac = new CustomerDAC(); CustomerEntity objCustomer = dac.Select(note.customer); if (objCustomer == null) { bNewCustomer = true; objCustomer = new CustomerEntity(); objCustomer.customer = note.customer; objCustomer.cyear = DateTime.Now.Year; objCustomer.sequence = 1; iDeliveryId = 1; } else { bNewCustomer = false; if (objCustomer.cyear == DateTime.Now.Year) { objCustomer.sequence = objCustomer.sequence + 1; iDeliveryId = objCustomer.sequence; } else { objCustomer.cyear = DateTime.Now.Year; objCustomer.sequence = 1; iDeliveryId = 1; } } using (var dmt = DMContext.GetTransaction()) { var trans = dmt.BeginTransaction(); if (bNewCustomer) { DMContext.Insert(objCustomer, null, trans); } else { DMContext.Update <CustomerEntity>(objCustomer, p => p.cid == objCustomer.cid, null, trans); } note.deliverid = iDeliveryId; int noteId = DMContext.Insert(note, null, trans); if (noteId > 0) { if (note.items != null) { foreach (DeliveryItem item in note.items) { item.noteid = noteId; DMContext.Insert(item, null, trans); } } trans.Commit(); bRet = true; } } return(bRet); }