示例#1
0
        /// <summary>
        /// Saves the catalog relation.
        /// </summary>
        /// <param name="dto">The dto.</param>
        internal static void SaveCatalogRelation(CatalogRelationDto dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException("dto", String.Format("CatalogRelationDto can not be null"));
            }

            CatalogRelationAdmin admin = new CatalogRelationAdmin(dto);

            EventContext.Instance.RaiseRelationUpdatingEvent(dto, new RelationEventArgs("updating"));
            admin.Save();
            EventContext.Instance.RaiseRelationUpdatedEvent(dto, new RelationEventArgs("updated"));

            string cacheKey = CatalogCache.CreateCacheKey("catalog-relation");

            // remove cached items
            if (dto.CatalogEntryRelation.Rows.Count > 0)
            {
                int catalogEntryId = ((CatalogRelationDto.CatalogEntryRelationRow)dto.CatalogEntryRelation.Rows[0]).ParentEntryId;
                CatalogCache.RemoveByPattern(String.Format(@"{0}-(\w*)-(\d+)-(\d+)-{1}-.*", cacheKey, catalogEntryId.ToString()));
            }

            if (dto.CatalogNodeRelation.Rows.Count > 0)
            {
                int catalogId     = ((CatalogRelationDto.CatalogNodeRelationRow)dto.CatalogNodeRelation.Rows[0]).CatalogId;
                int catalogNodeId = ((CatalogRelationDto.CatalogNodeRelationRow)dto.CatalogNodeRelation.Rows[0]).ChildNodeId;
                CatalogCache.RemoveByPattern(String.Format(@"{0}-(\w*)-{1}-{2}-(\d+)-.*", cacheKey, catalogId.ToString(), catalogNodeId.ToString()));
            }

            // TODO: remove cached items in case if CatalogRelations are deleted
        }