/// <summary> /// Sets the property value of the provided entity /// </summary> public static void SetPropertyValue <T>(this IHasEntityProperties <T> entity, string propertyName, object value) where T : BaseEntity { var typeName = entity.GetUnproxiedTypeName(); //does this property exist? var property = GetProperty(entity, propertyName) ?? new EntityProperty() { EntityId = entity.Id, EntityName = typeName, PropertyName = propertyName }; property.Value = JsonConvert.SerializeObject(value); var entityPropertyService = mobSocialEngine.ActiveEngine.Resolve <IEntityPropertyService>(); if (property.Id == 0) { entityPropertyService.Insert(property); } else { entityPropertyService.Update(property); } }
public static IList <Pair <ExtraField, string> > GetExtraFields(this IHasEntityProperties entity) { var entityProperties = entity.GetProperties(); var extraFieldService = DependencyResolver.Resolve <IExtraFieldService>(); var entityName = entity.GetType().Name; var typeExtraFields = extraFieldService.Get(x => x.EntityName == entityName).ToList(); var extraFieldList = new List <Pair <ExtraField, string> >(); foreach (var ef in typeExtraFields) { var fieldName = ef.GetDbFieldName(); var ep = entityProperties.FirstOrDefault(x => x.EntityName == entityName && x.PropertyName == fieldName); var fieldValue = ef.DefaultValue; if (ep == null) { fieldValue = ep.Value; } extraFieldList.Add(new Pair <ExtraField, string>() { First = ef, Second = fieldValue }); } return(extraFieldList); }
/// <summary> /// Gets the properties of entity /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <returns></returns> public static IList <EntityProperty> GetProperties <T>(this IHasEntityProperties <T> entity) where T : BaseEntity { var entityPropertyService = mobSocialEngine.ActiveEngine.Resolve <IEntityPropertyService>(); var typeName = entity.GetUnproxiedTypeName(); return(entityPropertyService.Get(x => x.EntityName == typeName && x.EntityId == entity.Id, null).ToList()); }
/// <summary> /// Gets the property with specified name for current entity /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <param name="propertyName"></param> /// <returns></returns> public static EntityProperty GetProperty <T>(this IHasEntityProperties <T> entity, string propertyName) where T : BaseEntity { var entityPropertyService = mobSocialEngine.ActiveEngine.Resolve <IEntityPropertyService>(); return (entityPropertyService.Get( x => x.EntityName == typeof(T).Name && x.EntityId == entity.Id && x.PropertyName == propertyName, null).FirstOrDefault()); }
/// <summary> /// Gets the properties of entity /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <returns></returns> public static IList <EntityProperty> GetProperties(this IHasEntityProperties entity) { var typeName = entity.GetType().Name; var entityPropertyService = DependencyResolver.Resolve <IEntityPropertyService>(); //get all in one go for performance reasons entity.EntityProperties = entity.EntityProperties ?? entityPropertyService.Get( x => x.EntityName == typeName && x.EntityId == entity.Id).ToList(); return(entity.EntityProperties); }
public static void DeleteProperty <T>(this IHasEntityProperties <T> entity, string propertyName, string propertyValue = null) where T : BaseEntity { var entityPropertyService = mobSocialEngine.ActiveEngine.Resolve <IEntityPropertyService>(); var typeName = entity.GetUnproxiedTypeName(); if (propertyValue == null) { entityPropertyService.Delete(x => x.EntityName == typeName && x.PropertyName == propertyName && x.EntityId == entity.Id); } else { entityPropertyService.Delete(x => x.EntityName == typeName && x.PropertyName == propertyName && x.Value == propertyValue && x.EntityId == entity.Id); } }
/// <summary> /// Gets property value as the target type /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <param name="propertyName"></param> /// <param name="defaultValue"></param> /// <returns></returns> public static T GetPropertyValueAs <T>(this IHasEntityProperties entity, string propertyName, T defaultValue = default(T)) { var entityPropertyService = mobSocialEngine.ActiveEngine.Resolve <IEntityPropertyService>(); var typeName = entity.GetType().BaseType?.Name; var entityProperty = entityPropertyService.Get( x => x.EntityName == typeName && x.EntityId == entity.Id && x.PropertyName == propertyName, null).FirstOrDefault(); if (entityProperty == null) { return(defaultValue); } return((T)Convert.ChangeType(entityProperty.Value, typeof(T))); }
/// <summary> /// Gets property value as the target type /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <param name="propertyName"></param> /// <param name="defaultValue"></param> /// <returns></returns> public static T GetPropertyValueAs <T>(this IHasEntityProperties entity, string propertyName, T defaultValue = default(T)) { if (entity == null) { return(defaultValue); } var entityProperty = GetProperty(entity, propertyName); if (entityProperty == null) { return(defaultValue); } return(JsonConvert.DeserializeAnonymousType(entityProperty.Value, defaultValue)); }
/// <summary> /// Gets property value as the target type /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <param name="propertyName"></param> /// <param name="defaultValue"></param> /// <returns></returns> public static T GetPropertyValueAs <T>(this IHasEntityProperties entity, string propertyName, T defaultValue = default(T)) { var entityPropertyService = mobSocialEngine.ActiveEngine.Resolve <IEntityPropertyService>(); var typeName = entity.GetUnproxiedTypeName(); if (typeName == null) { return(defaultValue); } var entityProperty = entityPropertyService.Get( x => x.EntityName == typeName && x.EntityId == entity.Id && x.PropertyName == propertyName, null).FirstOrDefault(); if (entityProperty == null) { return(defaultValue); } return(JsonConvert.DeserializeAnonymousType(entityProperty.Value, defaultValue)); }
public static void SetPropertyValue <T>(this IHasEntityProperties <T> entity, string propertyName, object value) where T : BaseEntity { //does this property exist? var property = GetProperty(entity, propertyName) ?? new EntityProperty() { EntityId = entity.Id, EntityName = typeof(T).Name, PropertyName = propertyName }; property.Value = value?.ToString(); var entityPropertyService = mobSocialEngine.ActiveEngine.Resolve <IEntityPropertyService>(); if (property.Id == 0) { entityPropertyService.Insert(property); } else { entityPropertyService.Update(property); } }
public static void SetPropertyValue(this IHasEntityProperties entity, string propertyName, object value) { //does this property exist? var property = GetProperty(entity, propertyName) ?? new EntityProperty() { EntityId = entity.Id, EntityName = entity.GetType().Name, PropertyName = propertyName }; property.Value = JsonConvert.SerializeObject(value); var entityPropertyService = DependencyResolver.Resolve <IEntityPropertyService>(); if (property.Id == 0) { entityPropertyService.Insert(property); entity.EntityProperties.Add(property); } else { entityPropertyService.Update(property); } }
/// <summary> /// Gets the property valueas stored /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <param name="propertyName"></param> /// <returns></returns> public static object GetPropertyValue <T>(this IHasEntityProperties <T> entity, string propertyName) where T : BaseEntity { var entityProperty = GetProperty(entity, propertyName); return(entityProperty?.Value); }
/// <summary> /// Gets the property valueas stored /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <param name="propertyName"></param> /// <returns></returns> public static object GetPropertyValue(this IHasEntityProperties entity, string propertyName) { var entityProperty = GetProperty(entity, propertyName); return(entityProperty?.Value); }
/// <summary> /// Gets the property with specified name for current entity /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <param name="propertyName"></param> /// <returns></returns> public static EntityProperty GetProperty(this IHasEntityProperties entity, string propertyName) { return(GetProperties(entity).FirstOrDefault(x => x.PropertyName == propertyName)); }