/// <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); }
public static moduleModel.Category ToModuleModel(this webModel.Category category) { var retVal = new moduleModel.Category(); retVal.InjectFrom(category); retVal.SeoInfos = category.SeoInfos; if (category.Links != null) { retVal.Links = category.Links.Select(x => x.ToCoreModel()).ToList(); } if (category.Properties != null) { retVal.PropertyValues = new List <moduleModel.PropertyValue>(); foreach (var property in category.Properties) { foreach (var propValue in property.Values) { propValue.ValueType = property.ValueType; //Need populate required fields propValue.PropertyId = property.Id; propValue.PropertyName = property.Name; retVal.PropertyValues.Add(propValue.ToCoreModel()); } } } if (category.Images != null) { retVal.Images = category.Images.Select(x => x.ToCoreModel()).ToList(); } return(retVal); }
public static moduleModel.Category ToModuleModel(this webModel.Category category) { var retVal = new moduleModel.Category(); retVal.InjectFrom(category); retVal.SeoInfos = category.SeoInfos; if (category.Links != null) { retVal.Links = category.Links.Select(x => x.ToModuleModel()).ToList(); } if (category.Properties != null) { retVal.PropertyValues = new List<moduleModel.PropertyValue>(); foreach (var property in category.Properties) { foreach(var propValue in property.Values) { propValue.ValueType = property.ValueType; //Need populate required fields propValue.PropertyName = property.Name; retVal.PropertyValues.Add(propValue.ToModuleModel()); } } } return retVal; }
public static moduleModel.Category ToModuleModel(this webModel.Category category) { var retVal = new moduleModel.Category(); retVal.InjectFrom(category); return retVal; }
public static moduleModel.Category ToModuleModel(this webModel.Category category) { var retVal = new moduleModel.Category(); retVal.InjectFrom(category); return(retVal); }
/// <summary> /// Converting to model type /// </summary> /// <param name="dbCategory">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.Category dbCategory, 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(dbCategory); retVal.CatalogId = catalog.Id; retVal.Catalog = catalog; retVal.ParentId = dbCategory.ParentCategoryId; retVal.IsActive = dbCategory.IsActive; 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(); } //Try to inherit taxType from parent category if (retVal.TaxType == null && retVal.Parents != null) { retVal.TaxType = retVal.Parents.Select(x => x.TaxType).Where(x => x != null).FirstOrDefault(); } #region Images if (dbCategory.Images != null) { retVal.Images = dbCategory.Images.OrderBy(x => x.SortOrder).Select(x => x.ToCoreModel()).ToList(); } #endregion return(retVal); }
/// <summary> /// Converting to model type /// </summary> /// <param name="dbCategory">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.Category dbCategory, 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(dbCategory); retVal.CatalogId = catalog.Id; retVal.Catalog = catalog; retVal.ParentId = dbCategory.ParentCategoryId; retVal.IsActive = dbCategory.IsActive; 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(); } //Try to inherit taxType from parent category if(retVal.TaxType == null && retVal.Parents != null) { retVal.TaxType = retVal.Parents.Select(x => x.TaxType).Where(x => x != null).FirstOrDefault(); } #region Images if (dbCategory.Images != null) { retVal.Images = dbCategory.Images.OrderBy(x => x.SortOrder).Select(x => x.ToCoreModel()).ToList(); } #endregion return retVal; }
/// <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; retVal.IsActive = dbCategoryBase.IsActive; 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(); } #region Images if (dbCategory.Images != null) { retVal.Images = dbCategory.Images.OrderBy(x => x.SortOrder).Select(x => x.ToCoreModel()).ToList(); } #endregion return retVal; }
/// <summary> /// Converting to model type /// </summary> /// <param name="dbCategory">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.Category dbCategory, bool convertProps = true) { var retVal = new coreModel.Category(); retVal.InjectFrom(dbCategory); retVal.CatalogId = dbCategory.CatalogId; retVal.Catalog = dbCategory.Catalog.ToCoreModel(); retVal.ParentId = dbCategory.ParentCategoryId; retVal.IsActive = dbCategory.IsActive; retVal.Virtual = dbCategory.Catalog.Virtual; retVal.Links = dbCategory.OutgoingLinks.Select(x => x.ToCoreModel(retVal)).ToList(); if (dbCategory.AllParents != null) { retVal.Parents = dbCategory.AllParents.Select(x => x.ToCoreModel()).ToArray(); retVal.Level = retVal.Parents.Count(); } //Try to inherit taxType from parent category if (retVal.TaxType == null && retVal.Parents != null) { retVal.TaxType = retVal.Parents.Select(x => x.TaxType).Where(x => x != null).FirstOrDefault(); } if (dbCategory.Images != null) { retVal.Images = dbCategory.Images.OrderBy(x => x.SortOrder).Select(x => x.ToCoreModel()).ToList(); } if (convertProps) { retVal.PropertyValues = dbCategory.CategoryPropertyValues.Select(x => x.ToCoreModel()).ToList(); var properties = new List <coreModel.Property>(); //Add inherited from catalog properties properties.AddRange(retVal.Catalog.Properties); //For parents categories if (retVal.Parents != null) { properties.AddRange(retVal.Parents.SelectMany(x => x.Properties)); } //Self properties properties.AddRange(dbCategory.Properties.Select(x => x.ToCoreModel())); //property override - need leave only property has a min distance to target category //Algorithm based on index property in resulting list (property with min index will more closed to category) var propertyGroups = properties.Select((x, index) => new { PropertyName = x.Name.ToLowerInvariant(), Property = x, Index = index }).GroupBy(x => x.PropertyName); retVal.Properties = propertyGroups.Select(x => x.OrderBy(y => y.Index).First().Property).ToList(); //Next need set Property in PropertyValues objects foreach (var propValue in retVal.PropertyValues.ToArray()) { propValue.Property = retVal.Properties.FirstOrDefault(x => x.IsSuitableForValue(propValue)); //Because multilingual dictionary values for all languages may not stored in db then need to 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); }
/// <summary> /// Converting to model type /// </summary> /// <param name="dbCategory">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.Category dbCategory, bool convertProps = true) { var retVal = new coreModel.Category(); retVal.InjectFrom(dbCategory); retVal.CatalogId = dbCategory.CatalogId; retVal.Catalog = dbCategory.Catalog.ToCoreModel(); retVal.ParentId = dbCategory.ParentCategoryId; retVal.IsActive = dbCategory.IsActive; retVal.Virtual = dbCategory.Catalog.Virtual; retVal.Links = dbCategory.OutgoingLinks.Select(x => x.ToCoreModel(retVal)).ToList(); if (dbCategory.AllParents != null) { retVal.Parents = dbCategory.AllParents.Select(x => x.ToCoreModel()).ToArray(); retVal.Level = retVal.Parents.Count(); } //Try to inherit taxType from parent category if(retVal.TaxType == null && retVal.Parents != null) { retVal.TaxType = retVal.Parents.Select(x => x.TaxType).Where(x => x != null).FirstOrDefault(); } if (dbCategory.Images != null) { retVal.Images = dbCategory.Images.OrderBy(x => x.SortOrder).Select(x => x.ToCoreModel()).ToList(); } if (convertProps) { retVal.PropertyValues = dbCategory.CategoryPropertyValues.Select(x => x.ToCoreModel()).ToList(); var properties = new List<coreModel.Property>(); //Add inherited from catalog properties properties.AddRange(retVal.Catalog.Properties); //For parents categories if (retVal.Parents != null) { properties.AddRange(retVal.Parents.SelectMany(x => x.Properties)); } //Self properties properties.AddRange(dbCategory.Properties.Select(x => x.ToCoreModel())); //property override - need leave only property has a min distance to target category //Algorithm based on index property in resulting list (property with min index will more closed to category) var propertyGroups = properties.Select((x, index) => new { PropertyName = x.Name.ToLowerInvariant(), Property = x, Index = index }).GroupBy(x => x.PropertyName); retVal.Properties = propertyGroups.Select(x => x.OrderBy(y => y.Index).First().Property).ToList(); //Next need set Property in PropertyValues objects foreach (var propValue in retVal.PropertyValues.ToArray()) { propValue.Property = retVal.Properties.FirstOrDefault(x => x.IsSuitableForValue(propValue)); //Because multilingual dictionary values for all languages may not stored in db then need to 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; }