Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public virtual void SaveAttribute<TPropType>(BaseEntity 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;
- 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 = CommonHelper.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);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement