/// <summary> /// Inserts an attribute /// </summary> /// <param name="attribute">attribute</param> public virtual void InsertAttribute(ArticleAttribute attribute) { if (attribute == null) { throw new ArgumentNullException("attribute"); } _articleAttributeRepository.Insert(attribute); //cache _cacheManager.RemoveByPattern(GENERICATTRIBUTE_PATTERN_KEY); //event notification _eventPublisher.EntityInserted(attribute); }
protected virtual void UpdateLocales(ArticleAttribute articleAttribute, ArticleAttributeModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(articleAttribute, x => x.Name, localized.Name, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(articleAttribute, x => x.Description, localized.Description, localized.LanguageId); } }
/// <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="siteId">Site identifier; pass 0 if this attribute will be available for all stores</param> public virtual void SaveAttribute <TPropType>(BaseEntity entity, string key, TPropType value, int siteId = 0) { if (entity == null) { throw new ArgumentNullException("entity"); } string keyGroup = entity.GetUnproxiedEntityType().Name; var props = GetAttributesForEntity(entity.Id, keyGroup) .ToList(); var prop = props.FirstOrDefault(ga => ga.Key.Equals(key, StringComparison.InvariantCultureIgnoreCase)); //should be culture invariant string valueStr = value.Convert <string>(); 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 ArticleAttribute() { EntityId = entity.Id, Key = key, KeyGroup = keyGroup, Value = valueStr }; InsertAttribute(prop); } } }
/// <summary> /// Updates the article attribute /// </summary> /// <param name="articleAttribute">Article attribute</param> public virtual void UpdateArticleAttribute(ArticleAttribute articleAttribute) { if (articleAttribute == null) { throw new ArgumentNullException("articleAttribute"); } _articleAttributeRepository.Update(articleAttribute); //cache _cacheManager.RemoveByPattern(ARTICLEATTRIBUTES_PATTERN_KEY); _cacheManager.RemoveByPattern(ARTICLEATTRIBUTEMAPPINGS_PATTERN_KEY); _cacheManager.RemoveByPattern(ARTICLEATTRIBUTEVALUES_PATTERN_KEY); _cacheManager.RemoveByPattern(ARTICLEATTRIBUTECOMBINATIONS_PATTERN_KEY); //event notification _eventPublisher.EntityUpdated(articleAttribute); }
public static ArticleAttribute ToEntity(this ArticleAttributeModel model, ArticleAttribute destination) { return(model.MapTo(destination)); }
public static ArticleAttributeModel ToModel(this ArticleAttribute entity) { return(entity.MapTo <ArticleAttribute, ArticleAttributeModel>()); }