/// <summary> /// 添加事物 /// </summary> /// <param name="key"></param> /// <param name="transaction"></param> public static void AddTransaction(string key, MyTransaction transaction) { var obj = CallContext.LogicalGetData(CONTEXT_TRANSACTIONS_COLLECTION); List <MyTransaction> MyTransactions = null; if (obj == null) { MyTransactions = new List <MyTransaction>(); MyTransactions.Add(transaction); } else { if (obj is List <MyTransaction> ) { MyTransactions = obj as List <MyTransaction>; if (MyTransactions.SingleOrDefault(t => t.DataBase == key) == null) { MyTransactions.Add(transaction); } } else { throw new InvalidCastException("字典转换失败"); } } CallContext.LogicalSetData(CONTEXT_TRANSACTIONS_COLLECTION, MyTransactions); }
private void AddTransaction() { // Create the object and update the database. Transaction t = new Transaction(); ModelService.AddTransaction(TheAccount, t); // Create the VM object and update the app/UI. Transaction_VM tvm = new Transaction_VM(); tvm.TheTransaction = t; MyTransactions.Add(tvm); MyParent.NotifyNumXacts(); }