/// <summary> /// Patch AssociationGroup type /// </summary> /// <param name="source"></param> /// <param name="target"></param> public static void Patch(this dataModel.AssociationGroup source, dataModel.AssociationGroup target) { var patchInjectionPolicy = new PatchInjection <dataModel.AssociationGroup>(x => x.Name, x => x.Description); target.InjectFrom(patchInjectionPolicy, source); if (!source.Associations.IsNullCollection()) { var associationComparer = AnonymousComparer.Create((dataModel.Association x) => x.ItemId); source.Associations.Patch(target.Associations, associationComparer, (sourceAssociation, targetAssociation) => sourceAssociation.Patch(targetAssociation)); } }
/// <summary> /// Converting to foundation type /// </summary> /// <param name="catalog"></param> /// <returns></returns> public static dataModel.Item ToDataModel(this coreModel.CatalogProduct product) { var retVal = new dataModel.Product(); var id = retVal.Id; retVal.InjectFrom(product); if (product.Id == null) { retVal.Id = id; } if(product.StartDate == default(DateTime)) { retVal.StartDate = DateTime.UtcNow; } retVal.IsActive = product.IsActive ?? true; retVal.IsBuyable = product.IsBuyable ?? true; retVal.TrackInventory = product.TrackInventory ?? true; retVal.MaxQuantity = product.MaxQuantity ?? 0; retVal.MinQuantity = product.MinQuantity ?? 0; retVal.ParentId = product.MainProductId; //Constant fields //Only for main product retVal.AvailabilityRule = (int)coreModel.AvailabilityRule.Always; retVal.MinQuantity = 1; retVal.MaxQuantity = 0; retVal.CatalogId = product.CatalogId; retVal.CategoryId = String.IsNullOrEmpty(product.CategoryId) ? null : product.CategoryId; #region ItemPropertyValues if (product.PropertyValues != null) { retVal.ItemPropertyValues = new ObservableCollection<dataModel.ItemPropertyValue>(); foreach (var propValue in product.PropertyValues) { var dbPropValue = propValue.ToDataModel<dataModel.ItemPropertyValue>() as dataModel.ItemPropertyValue; retVal.ItemPropertyValues.Add(dbPropValue); dbPropValue.ItemId = retVal.Id; } } #endregion #region Assets if (product.Assets != null) { retVal.Assets = new ObservableCollection<dataModel.Asset>(product.Assets.Select(x => x.ToDataModel())); } #endregion #region Images if (product.Images != null) { retVal.Images = new ObservableCollection<dataModel.Image>(product.Images.Select(x => x.ToDataModel())); } #endregion #region Links if (product.Links != null) { retVal.CategoryLinks = new ObservableCollection<dataModel.CategoryItemRelation>(); retVal.CategoryLinks.AddRange(product.Links.Select(x => x.ToDataModel(product))); } #endregion #region EditorialReview if (product.Reviews != null) { retVal.EditorialReviews = new ObservableCollection<dataModel.EditorialReview>(); retVal.EditorialReviews.AddRange(product.Reviews.Select(x => x.ToDataModel(retVal))); } #endregion #region Associations if (product.Associations != null) { retVal.AssociationGroups = new ObservableCollection<dataModel.AssociationGroup>(); var associations = product.Associations.ToArray(); for (int order = 0; order < associations.Count(); order++) { var association = associations[order]; var associationGroup = retVal.AssociationGroups.FirstOrDefault(x => x.Name == association.Name); if (associationGroup == null) { associationGroup = new dataModel.AssociationGroup { Name = association.Name, Description = association.Description, Priority = 1, }; retVal.AssociationGroups.Add(associationGroup); } var foundationAssociation = association.ToDataModel(); foundationAssociation.Priority = order; associationGroup.Associations.Add(foundationAssociation); } } #endregion return retVal; }
/// <summary> /// Converting to foundation type /// </summary> /// <param name="catalog"></param> /// <returns></returns> public static dataModel.Item ToDataModel(this coreModel.CatalogProduct product, PrimaryKeyResolvingMap pkMap) { var retVal = new dataModel.Item(); pkMap.AddPair(product, retVal); retVal.InjectFrom(product); if (product.StartDate == default(DateTime)) { retVal.StartDate = DateTime.UtcNow; } retVal.IsActive = product.IsActive ?? true; retVal.IsBuyable = product.IsBuyable ?? true; retVal.TrackInventory = product.TrackInventory ?? true; retVal.MaxQuantity = product.MaxQuantity ?? 0; retVal.MinQuantity = product.MinQuantity ?? 0; retVal.ParentId = product.MainProductId; //Constant fields //Only for main product retVal.AvailabilityRule = (int)coreModel.AvailabilityRule.Always; retVal.MinQuantity = 1; retVal.MaxQuantity = 0; retVal.CatalogId = product.CatalogId; retVal.CategoryId = String.IsNullOrEmpty(product.CategoryId) ? null : product.CategoryId; #region ItemPropertyValues if (product.PropertyValues != null) { retVal.ItemPropertyValues = new ObservableCollection <dataModel.PropertyValue>(); retVal.ItemPropertyValues.AddRange(product.PropertyValues.Where(x => !x.IsInherited).Select(x => x.ToDataModel(pkMap))); } #endregion #region Assets if (product.Assets != null) { retVal.Assets = new ObservableCollection <dataModel.Asset>(product.Assets.Where(x => !x.IsInherited).Select(x => x.ToDataModel(pkMap))); } #endregion #region Images if (product.Images != null) { retVal.Images = new ObservableCollection <dataModel.Image>(product.Images.Where(x => !x.IsInherited).Select(x => x.ToDataModel(pkMap))); } #endregion #region Links if (product.Links != null) { retVal.CategoryLinks = new ObservableCollection <dataModel.CategoryItemRelation>(); retVal.CategoryLinks.AddRange(product.Links.Select(x => x.ToDataModel(product))); } #endregion #region EditorialReview if (product.Reviews != null) { retVal.EditorialReviews = new ObservableCollection <dataModel.EditorialReview>(); retVal.EditorialReviews.AddRange(product.Reviews.Where(x => !x.IsInherited).Select(x => x.ToDataModel(retVal, pkMap))); } #endregion #region Associations if (product.Associations != null) { retVal.AssociationGroups = new ObservableCollection <dataModel.AssociationGroup>(); var associations = product.Associations.ToArray(); for (int order = 0; order < associations.Count(); order++) { var association = associations[order]; var associationGroup = retVal.AssociationGroups.FirstOrDefault(x => x.Name == association.Name); if (associationGroup == null) { associationGroup = new dataModel.AssociationGroup { Name = association.Name, Description = association.Description, Priority = 1, }; retVal.AssociationGroups.Add(associationGroup); } var foundationAssociation = association.ToDataModel(); foundationAssociation.Priority = order; associationGroup.Associations.Add(foundationAssociation); } } #endregion return(retVal); }
/// <summary> /// Converting to foundation type /// </summary> /// <param name="catalog"></param> /// <returns></returns> public static dataModel.Item ToDataModel(this coreModel.CatalogProduct product) { var retVal = new dataModel.Product(); var id = retVal.Id; retVal.InjectFrom(product); if (product.Id == null) { retVal.Id = id; } if (product.StartDate == default(DateTime)) { retVal.StartDate = DateTime.UtcNow; } retVal.IsActive = product.IsActive ?? true; retVal.IsBuyable = product.IsBuyable ?? true; retVal.TrackInventory = product.TrackInventory ?? true; retVal.MaxQuantity = product.MaxQuantity ?? 0; retVal.MinQuantity = product.MinQuantity ?? 0; retVal.ParentId = product.MainProductId; //Constant fields //Only for main product retVal.AvailabilityRule = (int)coreModel.AvailabilityRule.Always; retVal.MinQuantity = 1; retVal.MaxQuantity = 0; retVal.CatalogId = product.CatalogId; retVal.CategoryId = product.CategoryId; if (product.MainProduct != null) { retVal.Parent = product.MainProduct.ToDataModel(); } #region ItemPropertyValues if (product.PropertyValues != null) { retVal.ItemPropertyValues = new ObservableCollection <dataModel.ItemPropertyValue>(); foreach (var propValue in product.PropertyValues) { var dbPropValue = propValue.ToDataModel <dataModel.ItemPropertyValue>() as dataModel.ItemPropertyValue; retVal.ItemPropertyValues.Add(dbPropValue); dbPropValue.ItemId = retVal.Id; } } #endregion #region ItemAssets if (product.Assets != null) { var assets = product.Assets.ToArray(); retVal.ItemAssets = new ObservableCollection <dataModel.ItemAsset>(); for (int order = 0; order < assets.Length; order++) { var asset = assets[order]; var dbAsset = asset.ToDataModel(); dbAsset.SortOrder = order; retVal.ItemAssets.Add(dbAsset); } } #endregion #region Links if (product.Links != null) { retVal.CategoryLinks = new ObservableCollection <dataModel.CategoryItemRelation>(); retVal.CategoryLinks.AddRange(product.Links.Select(x => x.ToDataModel(product))); } #endregion #region EditorialReview if (product.Reviews != null) { retVal.EditorialReviews = new ObservableCollection <dataModel.EditorialReview>(); retVal.EditorialReviews.AddRange(product.Reviews.Select(x => x.ToDataModel(retVal))); } #endregion #region Associations if (product.Associations != null) { retVal.AssociationGroups = new ObservableCollection <dataModel.AssociationGroup>(); var associations = product.Associations.ToArray(); for (int order = 0; order < associations.Count(); order++) { var association = associations[order]; var associationGroup = retVal.AssociationGroups.FirstOrDefault(x => x.Name == association.Name); if (associationGroup == null) { associationGroup = new dataModel.AssociationGroup { Name = association.Name, Description = association.Description, Priority = 1, }; retVal.AssociationGroups.Add(associationGroup); } var foundationAssociation = association.ToDataModel(); foundationAssociation.Priority = order; associationGroup.Associations.Add(foundationAssociation); } } #endregion return(retVal); }