/// <summary> /// Gets the entity collection in the entity specified where the navigator specified is mapped on (e.g. 'Orders'). /// </summary> /// <param name="entity">The entity.</param> /// <param name="navigatorName">Name of the navigator.</param> /// <returns></returns> /// <remarks>Lazy loading friendly method, so it won't trigger lazy loading on selfservicing and will pre-create collection on adapter.</remarks> private IList GetEntityCollectionForNavigator(IEntityCore entity, string navigatorName) { IList toReturn = null; if (entity == null) { return(toReturn); } if (entity is IEntity2) { // adapter, simply read the property and return that. var property = _metaDataProvider.GetCachedPropertyForEntityType(entity.GetType(), navigatorName); if (property != null) { toReturn = property.GetValue(entity) as IList; } } else { // selfservicing. var relatedData = entity.GetRelatedData(); object containedMember = null; if (relatedData.TryGetValue(navigatorName, out containedMember)) { toReturn = containedMember as IList; } } return(toReturn); }
public override void AuditEntityFieldSet(IEntityCore entity, int fieldIndex, object originalValue) { AuditEntity auditInfo = new AuditEntity(); auditInfo.AuditorToUse = null; auditInfo.Table = ((IEntity)entity).Fields[fieldIndex].SourceObjectName; auditInfo.Field = ((IEntity)entity).Fields[fieldIndex].Name; // save old and new data if (originalValue != null) auditInfo.OldData = originalValue.ToString().Substring(0, Math.Min(originalValue.ToString().Length, AuditFields.OldData.MaxLength)); if (entity.GetCurrentFieldValue(fieldIndex) != null) auditInfo.NewData = entity.GetCurrentFieldValue(fieldIndex).ToString().Substring(0, Math.Min(entity.GetCurrentFieldValue(fieldIndex).ToString().Length, AuditFields.NewData.MaxLength)); else auditInfo.NewData = null; // get the primary keys fields var prop = entity.GetType().GetProperty("Fields"); var fields = ((IEntityFields)prop.GetValue(entity, null)).Where(x => x.IsPrimaryKey); string key = ""; foreach (EntityField field in fields) { key += (key != "" ? "," : "") + field.CurrentValue; } auditInfo.Key = key; // save currently logged in user if (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.User != null) auditInfo.CreatedBy = System.Web.HttpContext.Current.User.Identity.Name.ToLower(); else auditInfo.CreatedBy = ""; auditInfo.CreatedDate = DateTime.UtcNow; _auditInfoEntities.Add(auditInfo); }
internal bool IsAuditActionValid(IEntityCore entity) { if (entity == null) { return(false); } //We should skip the entites of TAuditInfoEntity type if ((entity != null) && (entity.GetType().Equals(typeof(AuditInfoEntity)))) { return(false); } return(true); }
/// <summary> /// Gets the validation attributes of a field in an entity. /// </summary> /// <param name="involvedEntity">The involved entity.</param> /// <param name="fieldName">Name of the field.</param> /// <returns>The validation attributes.</returns> public static IEnumerable <ValidationAttribute> GetValidationAttributes(IEntityCore involvedEntity, string fieldName) { return(MetaDataHelper.GetValidationAttributes(involvedEntity.GetType(), fieldName)); }
protected virtual bool IsEntityAuditable(IEntityCore entity) { return(includedEntityTypes == null || includedEntityTypes.Contains(entity.GetType())); }
/// <summary> /// Initializes a new instance of the <see cref="EntityMemberProvider"/> class. /// </summary> /// <param name="wrappedEntity">The wrapped entity.</param> public EntityMemberProvider(IEntityCore wrappedEntity) { _wrappedEntity = wrappedEntity; _propertyDescriptors = PropertyDescriptorCache.GetDescriptors(wrappedEntity.GetType()); }