/// <summary> /// Copy one product item to another for the uses of content lifecycle management /// </summary> /// <param name="source">Product item to copy from</param> /// <param name="destination">Product item to copy to</param> public void Copy(ProductItem source, ProductItem destination) { destination.Urls.ClearDestinationUrls(source.Urls, this.Delete); source.Urls.CopyTo(destination.Urls, destination); ContentLinksExtensions.CopyContentLink("ProductImage", source, destination); destination.Price = source.Price; destination.QuantityInStock = source.QuantityInStock; }
/// <summary> /// Installs the taxonomies. /// </summary> /// <param name="initializer">The initializer.</param> protected void InstallCustomTaxonomies(SiteInitializer initializer) { //installs the default Tags and Category taxonomies this.InstallTaxonomy(initializer, typeof(ProductItem)); var metaMan = initializer.MetadataManager; var taxMan = initializer.TaxonomyManager; var flatTaxonomy = this.CreateTaxonomy <FlatTaxonomy>(initializer, "Colors", ColorsTaxonomyId, "Color"); //if the module is reinstalled the taxa will be re-added so a check is needed if (initializer.TaxonomyManager.GetTaxonomy <FlatTaxonomy>(ColorsTaxonomyId).Taxa.Count() == 0) { var taxon1 = initializer.TaxonomyManager.CreateTaxon <FlatTaxon>(); taxon1.Title = "Red"; taxon1.Name = "Red"; var taxon2 = initializer.TaxonomyManager.CreateTaxon <FlatTaxon>(); taxon2.Title = "Blue"; taxon2.Name = "Blue"; flatTaxonomy.Taxa.Add(taxon1); flatTaxonomy.Taxa.Add(taxon2); } var type = metaMan.GetMetaType(typeof(ProductItem)); if (type == null) { type = metaMan.CreateMetaType(typeof(ProductItem)); } if (!type.Fields.ToList().Any(fld => fld.FieldName == "Colors")) { var field = metaMan.CreateMetafield("Colors"); field.TaxonomyProvider = taxMan.Provider.Name; field.TaxonomyId = ColorsTaxonomyId; field.IsSingleTaxon = false; type.Fields.Add(field); } if (!type.Fields.ToList().Any(fld => fld.FieldName == "ProductImage")) { type.Fields.Add(ContentLinksExtensions.CreateContentLinkField("ProductImage", "OpenAccessDataProvider", metaMan, RelationshipType.OneToOne)); } }
/// <summary> /// Changes the profile avatar. /// </summary> /// <param name="userId">The user identifier.</param> /// <param name="image">The profile image.</param> /// <param name="userProfileManager">The user profile manager.</param> private void ChangeProfileAvatar(Guid userId, Image image, UserProfileManager userProfileManager) { User user = SecurityManager.GetUser(userId); if (user != null && image != null) { SitefinityProfile profile = userProfileManager.GetUserProfile <SitefinityProfile>(user); if (profile != null) { ContentLink avatarLink = ContentLinksExtensions.CreateContentLink(profile, image); profile.Avatar = avatarLink; // Setting the Avatar does not modify the actual Profile persistent object and cache entries that depend on the Profile are not invalidated. // By setting another property of the Profile we force all cache entries that depend ot this profile to be invalidated. profile.LastModified = DateTime.UtcNow; } } }