/// <summary> /// Adds new transaction to table storage or updates an existing item. /// Throws exception when item is not valid, resolving customer external ID failed or if table storage operation fails. /// </summary> /// <param name="t">Transaction item to add/update</param> public void AddOrUpdateTransaction(Transaction t) { EnsureTransactionHasCustomerInternalID(t); t.EnsureEntityValidForStorage(); var ent = new TransactionTableEntity(t.ID.Value, t.Date.Value, t.InternalRef.Value) { MvaNumber = t.MvaNumber, Amount = t.Amount, Description = t.Description, CustomerNumber = t.CustomerNumber, AccountID = t.AccountID, ProductID = t.ProductID, NotInvoiceable = t.NotInvoiceable, ExternalRecordID = t.ExternalRecordID, }; AddOrUpdateTransaction(ent); }
/// <summary> /// Adds the transaction item to search index. Can also be used for updating existing items by specifying the Transaction.ID value. /// Throws exception when item is not valid, resolving customer external ID failed or if search index operation fails. /// </summary> /// <param name="t"></param> public void AddToIndex(Transaction t) { t.EnsureEntityValidForStorage(); Guid internalID; if (t.InternalRef.HasValue) { internalID = t.InternalRef.Value; } else { Customer c = new CustomerRepository().GetCustomerByExternalID(t.MvaNumber.Value, t.ExternalRef); if (c == null) { throw new Exception(string.Format("Failed to resolve customer external ID ({0}) to internal", t.ExternalRef)); } internalID = c.InternalID.Value; } var tableEnt = new TransactionTableEntity(t.ID.Value, t.Date.Value, internalID) { Amount = t.Amount, CustomerNumber = t.CustomerNumber, AccountID = t.AccountID, Description = t.Description, MvaNumber = t.MvaNumber, ProductID = t.ProductID }; AddToIndex(tableEnt); }
/// <summary> /// Adds the transaction item to WebJob queues. Workers process each queue item and add them to transaction table and search index. /// Can also be used for updating existing items if Transaction.ID is specified. /// Also generates ID if it's null and sets Date to DateTime.Now if it isn't set. /// </summary> /// <param name="t">Transaction item to add/update</param> /// <returns>The item that was added to queue. Throws exception when item is not valid or if adding to queue failed.</returns> public Transaction AddTransactionToUpdateQueue(Transaction t) { t.EnsureEntityValidForStorage(true); SerializeTransactionAndAddToQueue(t); return t; }