public AptifyGenericEntityBase GetEntity(string name, int id, IAptifyTransaction transaction) { this.application.UserCredentials.DefaultTransactionID = transaction == null ? String.Empty : transaction.TransactionName; return(this.application.GetEntityObject(name, ( long )id)); }
public AptifyGenericEntityBase GetEntity(object entity, IAptifyTransaction transaction) { var aptifyEntity = this.Tables.GetEntityMetadata(entity); // Reflection magic to get the ID. Let's hope nobody checks this. var prop = ( from p in entity.GetType( ).GetProperties( ) where p.Name.Equals("id", StringComparison.InvariantCultureIgnoreCase) select p).FirstOrDefault( ); if (prop == null) { throw new InvalidOperationException("Entity does not have an ID property"); } if (!prop.PropertyType.IsValueType) { throw new InvalidOperationException("Entity's ID is not a valid type. Please use an int or long"); } long id = Convert.ToInt64(prop.GetValue(entity, null)); // TODO: Fix this hack this.application.UserCredentials.DefaultTransactionID = transaction != null ? transaction.TransactionName : String.Empty; return(this.application.get_Entity(aptifyEntity.Id) .GetEntityObject(id)); }
/// <summary> /// Save the given entity to the database /// </summary> /// <param name="genericEntity">Generic entity to save</param> /// <param name="transaction">Transaction to save within</param> /// <returns>The new ID of the entity</returns> public int SaveEntity(AptifyGenericEntityBase genericEntity, IAptifyTransaction transaction) { string message = String.Empty; string transactionName = (transaction == null) ? null : transaction.TransactionName; // Validate the entity for errors if (!genericEntity.Validate(ref message)) { throw new DataException(message); } // Try saving the entity if (!genericEntity.Save(false, ref message, transactionName)) { // It's possible the error message is not returned if (String.IsNullOrEmpty(message)) { message = genericEntity.LastError; } throw new DataException(message); } return(( int )genericEntity.RecordID); }