/// <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;
        }
        /// <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);
        }
        public coreModel.Property GetById(string propertyId)
        {
            coreModel.Property retVal = null;
            using (var repository = _catalogRepositoryFactory())
            {
                var dbProperty = repository.GetPropertiesByIds(new string[] { propertyId }).FirstOrDefault();
                if (dbProperty != null)
                {
                    dataModel.Catalog  dbCatalog  = null;
                    dataModel.Category dbCategory = null;
                    dbCatalog = repository.GetPropertyCatalog(dbProperty.Id);
                    if (dbCatalog == null)
                    {
                        dbCategory = repository.GetPropertyCategory(dbProperty.Id);
                        dbCatalog  = repository.GetCatalogById(dbCategory.CatalogId) as dataModel.Catalog;
                    }

                    var catalog  = dbCatalog.ToCoreModel();
                    var category = dbCategory != null?dbCategory.ToCoreModel(catalog) : null;

                    retVal = dbProperty.ToCoreModel(catalog, category);
                }
            }
            return(retVal);
        }
		public void CatalogPatchTest()
		{
			var chageTracker = new ObservableChangeTracker
			{
				RemoveAction = (x) =>
				{
					Console.WriteLine(x.ToString());
				}
			};

			var dbCatalog1 = new dataModel.Catalog
			{
				 Name = "catalog1",
				 DefaultLanguage = "en-us"
			};
			dbCatalog1.CatalogLanguages.Add(new dataModel.CatalogLanguage { Language = "en-us" });
			dbCatalog1.CatalogLanguages.Add(new dataModel.CatalogLanguage { Language = "fr-fr" });

			var dbCatalog2 = new dataModel.Catalog
			{
				Name = "unknow"
			};
			dbCatalog2.CatalogLanguages.Add(new dataModel.CatalogLanguage { Language = "ru-ru" });

			chageTracker.Attach(dbCatalog2);
			dbCatalog1.Patch(dbCatalog2);

		}
        /// <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));
            }
        }
Exemple #6
0
        public void CatalogPatchTest()
        {
            var chageTracker = new ObservableChangeTracker
            {
                RemoveAction = (x) =>
                {
                    Console.WriteLine(x.ToString());
                }
            };

            var dbCatalog1 = new dataModel.Catalog
            {
                Name            = "catalog1",
                DefaultLanguage = "en-us"
            };

            dbCatalog1.CatalogLanguages.Add(new dataModel.CatalogLanguage {
                Language = "en-us"
            });
            dbCatalog1.CatalogLanguages.Add(new dataModel.CatalogLanguage {
                Language = "fr-fr"
            });

            var dbCatalog2 = new dataModel.Catalog
            {
                Name = "unknow"
            };

            dbCatalog2.CatalogLanguages.Add(new dataModel.CatalogLanguage {
                Language = "ru-ru"
            });

            chageTracker.Attach(dbCatalog2);
            dbCatalog1.Patch(dbCatalog2);
        }
        /// <summary>
        /// Converting to foundation type
        /// </summary>
        /// <param name="catalog"></param>
        /// <returns></returns>
        public static dataModel.CatalogBase ToDataModel(this coreModel.Catalog catalog)
        {
            if (catalog == null)
            {
                throw new ArgumentNullException("catalog");
            }

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

            dataModel.CatalogBase    retVal;
            dataModel.Catalog        dbCatalog     = null;
            dataModel.VirtualCatalog dbVirtCatalog = null;

            if (catalog.Virtual)
            {
                dbVirtCatalog = new dataModel.VirtualCatalog();
                retVal        = dbVirtCatalog;
            }
            else
            {
                dbCatalog = new dataModel.Catalog();

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

            //Because EF mapping schema not automatically linked foreign keys, we should generate manually id and  set links manually
            var id = retVal.Id;

            retVal.InjectFrom(catalog);
            if (catalog.Id == null)
            {
                retVal.Id = id;
            }

            retVal.DefaultLanguage = catalog.DefaultLanguage.LanguageCode;

            if (dbCatalog != null && catalog.Languages != null)
            {
                dbCatalog.CatalogLanguages = new ObservableCollection <dataModel.CatalogLanguage>();
                foreach (var dbCatalogLanguage in catalog.Languages.Select(x => x.ToDataModel()))
                {
                    dbCatalogLanguage.CatalogId = retVal.Id;
                    dbCatalog.CatalogLanguages.Add(dbCatalogLanguage);
                }
            }

            retVal.Name = catalog.Name;

            return(retVal);
        }
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="catalogBase"></param>
        /// <returns></returns>
        public static coreModel.Catalog ToCoreModel(this dataModel.Catalog dbCatalog, bool convertProps = true)
        {
            if (dbCatalog == null)
            {
                throw new ArgumentNullException("catalog");
            }

            var retVal = new coreModel.Catalog();

            retVal.Id        = dbCatalog.Id;
            retVal.Name      = dbCatalog.Name;
            retVal.IsVirtual = dbCatalog.Virtual;
            retVal.Languages = new List <coreModel.CatalogLanguage>();

            var defaultLanguage = (new dataModel.CatalogLanguage {
                Language = string.IsNullOrEmpty(dbCatalog.DefaultLanguage) ? "en-us" : dbCatalog.DefaultLanguage
            }).ToCoreModel(retVal);

            defaultLanguage.IsDefault = true;
            retVal.Languages          = new List <coreModel.CatalogLanguage>();
            retVal.Languages.Add(defaultLanguage);

            //populate additional languages
            foreach (var catalogLanguage in dbCatalog.CatalogLanguages.Where(x => x.Language != defaultLanguage.LanguageCode).Select(x => x.ToCoreModel(retVal)))
            {
                catalogLanguage.Catalog = retVal;
                retVal.Languages.Add(catalogLanguage);
            }


            if (convertProps)
            {
                retVal.PropertyValues = dbCatalog.CatalogPropertyValues.Select(x => x.ToCoreModel()).ToList();
                //Self properties
                retVal.Properties = dbCatalog.Properties.Where(x => x.CategoryId == null).OrderBy(x => x.Name).Select(x => x.ToCoreModel(new dataModel.Catalog[] { dbCatalog }, new dataModel.Category[] { })).ToList();

                //Next need set Property in PropertyValues objects
                foreach (var propValue in retVal.PropertyValues.ToArray())
                {
                    propValue.Property = retVal.Properties.FirstOrDefault(x => x.IsSuitableForValue(propValue));
                    //Return each localized value for selecte dictionary value
                    //Because multilingual dictionary values for all languages may not stored in db need add it in result manually from property dictionary values
                    var localizedDictValues = propValue.TryGetAllLocalizedDictValues();
                    foreach (var localizedDictValue in localizedDictValues)
                    {
                        if (!retVal.PropertyValues.Any(x => x.ValueId == localizedDictValue.ValueId && x.LanguageCode == localizedDictValue.LanguageCode))
                        {
                            retVal.PropertyValues.Add(localizedDictValue);
                        }
                    }
                }
            }

            return(retVal);
        }
Exemple #9
0
        public dataModel.Catalog GetPropertyCatalog(string propId)
        {
            dataModel.Catalog retVal = null;
            var propSet = PropertySets.FirstOrDefault(x => x.PropertySetProperties.Any(y => y.PropertyId == propId));

            if (propSet != null)
            {
                var catalogId = Catalogs.OfType <dataModel.Catalog>()
                                .Where(x => x.PropertySetId == propSet.Id)
                                .Select(x => x.Id).FirstOrDefault();
                if (catalogId != null)
                {
                    retVal = GetCatalogById(catalogId) as dataModel.Catalog;
                }
            }
            return(retVal);
        }
		public void Tst1()
		{
			var repository = GetRepository();
			var catalog = new dataModel.Catalog
			{
				Id = "sss",
				 Name = "test",
				 DefaultLanguage = "en-us"
			};
			var language = new dataModel.CatalogLanguage
			{
				 Language = "sss"
			};
			catalog.CatalogLanguages.Add(language);
			repository.Add(catalog);
			repository.UnitOfWork.Commit();
		}
Exemple #11
0
        public void Tst1()
        {
            var repository = GetRepository();
            var catalog    = new dataModel.Catalog
            {
                Id              = "sss",
                Name            = "test",
                DefaultLanguage = "en-us"
            };
            var language = new dataModel.CatalogLanguage
            {
                Language = "sss"
            };

            catalog.CatalogLanguages.Add(language);
            repository.Add(catalog);
            repository.UnitOfWork.Commit();
        }
Exemple #12
0
        public void SetCatalogProperty(dataModel.Catalog catalog, dataModel.Property property)
        {
            if (catalog.PropertySet == null)
            {
                var propertySet = new dataModel.PropertySet
                {
                    Name       = catalog.Name + " property set",
                    TargetType = "Catalog"
                };
                Add(propertySet);
                catalog.PropertySetId = propertySet.Id;
            }

            var propertySetProperty = new dataModel.PropertySetProperty
            {
                PropertySetId = catalog.PropertySetId,
                PropertyId    = property.Id
            };

            Add(propertySetProperty);
        }
        /// <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");
            }

            target.Name            = source.Name;
            target.DefaultLanguage = source.DefaultLanguage;

            //Languages patch
            if (!source.CatalogLanguages.IsNullCollection())
            {
                var languageComparer = AnonymousComparer.Create((dataModel.CatalogLanguage x) => x.Language);
                source.CatalogLanguages.Patch(target.CatalogLanguages, languageComparer,
                                              (sourceLang, targetlang) => sourceLang.Patch(targetlang));
            }

            //Property values
            if (!source.CatalogPropertyValues.IsNullCollection())
            {
                source.CatalogPropertyValues.Patch(target.CatalogPropertyValues, (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue));
            }
        }
        /// <summary>
        /// Converting to foundation type
        /// </summary>
        /// <param name="catalog"></param>
        /// <returns></returns>
        public static dataModel.CatalogBase ToDataModel(this coreModel.Catalog catalog)
        {
            if (catalog == null)
                throw new ArgumentNullException("catalog");

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

            dataModel.CatalogBase retVal;
            dataModel.Catalog dbCatalog = null;
            dataModel.VirtualCatalog dbVirtCatalog = null;

            if (catalog.Virtual)
            {
                dbVirtCatalog = new dataModel.VirtualCatalog();
                retVal = dbVirtCatalog;
            }
            else
            {
                dbCatalog = new dataModel.Catalog();

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

            //Because EF mapping schema not automatically linked foreign keys, we should generate manually id and  set links manually
            var id = retVal.Id;
            retVal.InjectFrom(catalog);
            if (catalog.Id == null)
            {
                retVal.Id = id;
            }

			retVal.DefaultLanguage = catalog.DefaultLanguage.LanguageCode;

            if (dbCatalog != null && catalog.Languages != null)
            {
                dbCatalog.CatalogLanguages = new ObservableCollection<dataModel.CatalogLanguage>();
                foreach (var dbCatalogLanguage in catalog.Languages.Select(x => x.ToDataModel()))
                {
                    dbCatalogLanguage.CatalogId = retVal.Id;
                    dbCatalog.CatalogLanguages.Add(dbCatalogLanguage);
                }
            }

            retVal.Name = catalog.Name;

            return retVal;
        }