Пример #1
0
        /// <summary>
        /// Converting to foundation type
        /// </summary>
        /// <param name="catalog"></param>
        /// <returns></returns>
        public static dataModel.Catalog ToDataModel(this coreModel.Catalog catalog, PrimaryKeyResolvingMap pkMap)
        {
            if (catalog == null)
            {
                throw new ArgumentNullException("catalog");
            }

            if (catalog.DefaultLanguage == null)
            {
                throw new NullReferenceException("DefaultLanguage");
            }

            var retVal = new dataModel.Catalog();

            pkMap.AddPair(catalog, retVal);

            if (catalog.PropertyValues != null)
            {
                retVal.CatalogPropertyValues = new ObservableCollection <dataModel.PropertyValue>();
                retVal.CatalogPropertyValues.AddRange(catalog.PropertyValues.Select(x => x.ToDataModel(pkMap)));
            }

            retVal.InjectFrom(catalog);
            retVal.Virtual = catalog.IsVirtual;

            retVal.DefaultLanguage = catalog.DefaultLanguage.LanguageCode;

            if (catalog.Languages != null)
            {
                retVal.CatalogLanguages = new ObservableCollection <dataModel.CatalogLanguage>();
                retVal.CatalogLanguages.AddRange(catalog.Languages.Select(x => x.ToDataModel()));
            }

            return(retVal);
        }
Пример #2
0
        /// <summary>
        /// Patch CatalogBase type
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        public static void Patch(this dataModel.Catalog source, dataModel.Catalog target)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            var patchInjectionPolicy = new PatchInjection <dataModel.Catalog>(x => x.Name, x => x.DefaultLanguage);

            target.InjectFrom(patchInjectionPolicy, source);

            //Languages patch
            var sourceCatalog = source as dataModel.Catalog;
            var targetCatalog = target as dataModel.Catalog;

            if (sourceCatalog != null && targetCatalog != null && !sourceCatalog.CatalogLanguages.IsNullCollection())
            {
                var languageComparer = AnonymousComparer.Create((dataModel.CatalogLanguage x) => x.Language);
                sourceCatalog.CatalogLanguages.Patch(targetCatalog.CatalogLanguages, languageComparer,
                                                     (sourceLang, targetlang) => sourceLang.Patch(targetlang));
            }

            //Property values
            if (sourceCatalog != null && !sourceCatalog.CatalogPropertyValues.IsNullCollection())
            {
                sourceCatalog.CatalogPropertyValues.Patch(targetCatalog.CatalogPropertyValues, (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue));
            }
        }
Пример #3
0
        /// <summary>
        /// Converting to foundation type
        /// </summary>
        /// <param name="catalog"></param>
        /// <returns></returns>
        public static dataModel.Catalog ToDataModel(this coreModel.Catalog catalog, PrimaryKeyResolvingMap pkMap)
        {
            if (catalog == null)
                throw new ArgumentNullException("catalog");

			if(catalog.DefaultLanguage == null)
				throw new NullReferenceException("DefaultLanguage");

            var retVal = new dataModel.Catalog();
            pkMap.AddPair(catalog, retVal);

            if (catalog.PropertyValues != null)
            {
                retVal.CatalogPropertyValues = new ObservableCollection<dataModel.PropertyValue>();
                retVal.CatalogPropertyValues.AddRange(catalog.PropertyValues.Select(x => x.ToDataModel(pkMap)));
            }

            retVal.InjectFrom(catalog);

            retVal.DefaultLanguage = catalog.DefaultLanguage.LanguageCode;

            if (catalog.Languages != null)
            {
                retVal.CatalogLanguages = new ObservableCollection<dataModel.CatalogLanguage>();
                retVal.CatalogLanguages.AddRange(catalog.Languages.Select(x => x.ToDataModel()));
            }

            return retVal;
        }