/// <summary> /// Save attribute value /// </summary> /// <typeparam name="TPropType">Property type</typeparam> /// <param name="entity">Entity</param> /// <param name="key">Key</param> /// <param name="value">Value</param> /// <param name="storeId">Store identifier; pass 0 if this attribute will be available for all stores</param> public virtual void SaveAttribute <TPropType>(FullAuditedEntity entity, string key, TPropType value, int storeId = 0) { if (entity == null) { throw new ArgumentNullException("entity"); } if (key == null) { throw new ArgumentNullException("key"); } string keyGroup = entity.GetUnproxiedEntityType().Name; SaveAttribute(entity.Id, keyGroup, key, value, storeId); //var props = GetAttributesForEntity(entity.Id, keyGroup) // .Where(x => x.StoreId == storeId) // .ToList(); //var prop = props.FirstOrDefault(ga => // ga.Key.Equals(key, StringComparison.InvariantCultureIgnoreCase)); //should be culture invariant //var valueStr = CommonUtil.To<string>(value); //if (prop != null) //{ // if (string.IsNullOrWhiteSpace(valueStr)) // { // //delete // DeleteAttribute(prop); // } // else // { // //update // prop.Value = valueStr; // UpdateAttribute(prop); // } //} //else //{ // if (!string.IsNullOrWhiteSpace(valueStr)) // { // //insert // prop = new GenericAttribute // { // EntityId = entity.Id, // Key = key, // KeyGroup = keyGroup, // Value = valueStr, // StoreId = storeId, // }; // InsertAttribute(prop); // } //} }
/// <summary> /// Get an attribute of an entity /// </summary> /// <typeparam name="TPropType">Property type</typeparam> /// <param name="entity">Entity</param> /// <param name="key">Key</param> /// <param name="genericAttributeService">GenericAttributeService</param> /// <param name="storeId">Load a value specific for a certain store; pass 0 to load a value shared for all stores</param> /// <returns>Attribute</returns> public static TPropType GetAttribute <TPropType>(this FullAuditedEntity <long> entity, string key, GenericAttributeDomianService genericAttributeService, int storeId = 0) { if (entity == null) { throw new ArgumentNullException("entity"); } string keyGroup = entity.GetUnproxiedEntityType().Name; return(GetAttribute <TPropType>((int)entity.Id, keyGroup, key, genericAttributeService, storeId)); }
/// <summary> /// Save attribute value /// </summary> /// <typeparam name="TPropType">Property type</typeparam> /// <param name="entity">Entity</param> /// <param name="key">Key</param> /// <param name="value">Value</param> /// <param name="storeId">Store identifier; pass 0 if this attribute will be available for all stores</param> public virtual void SaveAttribute <TPropType>(FullAuditedEntity <long> entity, string key, TPropType value, int storeId = 0) { if (entity == null) { throw new ArgumentNullException("entity"); } if (key == null) { throw new ArgumentNullException("key"); } string keyGroup = entity.GetUnproxiedEntityType().Name; SaveAttribute((int)entity.Id, keyGroup, key, value, storeId); }