コード例 #1
0
        /// <summary>
        /// Patch changes
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        public static void Patch(this dataModel.CategoryBase source, dataModel.CategoryBase target)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            var dbSource = source as dataModel.Category;
            var dbTarget = target as dataModel.Category;

            if (dbSource != null && dbTarget != null)
            {
                var patchInjectionPolicy = new PatchInjection <dataModel.Category>(x => x.Code, x => x.Name, x => x.IsActive);
                target.InjectFrom(patchInjectionPolicy, source);

                if (!dbSource.CategoryPropertyValues.IsNullCollection())
                {
                    dbSource.CategoryPropertyValues.Patch(dbTarget.CategoryPropertyValues, (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue));
                }

                if (!dbSource.OutgoingLinks.IsNullCollection())
                {
                    dbSource.OutgoingLinks.Patch(dbTarget.OutgoingLinks, new LinkedCategoryComparer(), (sourceLink, targetLink) => sourceLink.Patch(targetLink));
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="dbCategoryBase">The database category base.</param>
        /// <param name="catalog">The catalog.</param>
        /// <param name="properties">The properties.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">catalog</exception>
        public static coreModel.Category ToCoreModel(this dataModel.CategoryBase dbCategoryBase, coreModel.Catalog catalog,
                                                     coreModel.Property[] properties = null, dataModel.Category[] allParents = null)
        {
            if (catalog == null)
            {
                throw new ArgumentNullException("catalog");
            }

            var retVal = new coreModel.Category();

            retVal.InjectFrom(dbCategoryBase);
            retVal.CatalogId = catalog.Id;
            retVal.Catalog   = catalog;
            retVal.ParentId  = dbCategoryBase.ParentCategoryId;

            var dbCategory = dbCategoryBase as dataModel.Category;

            if (dbCategory != null)
            {
                retVal.PropertyValues = dbCategory.CategoryPropertyValues.Select(x => x.ToCoreModel(properties)).ToList();
                retVal.Virtual        = catalog.Virtual;
                retVal.Links          = dbCategory.OutgoingLinks.Select(x => x.ToCoreModel(retVal)).ToList();
            }

            if (allParents != null)
            {
                retVal.Parents = allParents.Select(x => x.ToCoreModel(catalog)).ToArray();
            }

            return(retVal);
        }