Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ayo Adesina 445 posts 1059 karma points
    May 11, 2017 @ 16:05
    Ayo Adesina
    0

    Archetype - Programmatic Manipulating Values

    Hi Guys,

    I have added some code to the Umbraco Event

    ContentService.Saving
    

    So I'm intercepting the event when the user saves an Item in the back office, the main reason I am doing this is to set default images if the user does not enter one, this is working great so far.

    However I have just added another document type that has an Archetype Property one of those properties is an image.

    How can I do this for Archetype?

    This is what I have done so far, the regular documents work fine.

            private void ContentService_Saving(IContentService sender, SaveEventArgs<IContent> e)
        {
            var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
            var defaultValues = umbracoHelper.GetDefaultValues();
    
            foreach (var content in e.SavedEntities.Where(c => c.ContentType.Alias == "scholar" || c.ContentType.Alias == "newsPost" || c.ContentType.Alias == "eventItem" || c.ContentType.Alias == "eventSpeaker" || c.ContentType.Alias == "podcastGroup"))
            {
    
    
                if (content.HasProperty("profilePicture") && string.IsNullOrWhiteSpace(content.GetValue<string>("profilePicture")))
                {
                    content.SetValue("profilePicture", defaultValues.GetProperty("defaultScholarProfileImage").Value);
                    sender.Save(content);
                }
    
                if (content.HasProperty("listingImage") && string.IsNullOrWhiteSpace(content.GetValue<string>("listingImage")))
                {
                    content.SetValue("listingImage", defaultValues.GetProperty("defaultNewsListingImage").Value);
                    sender.Save(content);
                }
    
    
                if (content.HasProperty("podcastFiles") && content.GetValue<ArchetypeModel>("podcastFiles").Count() > 1)
                {
    
                    foreach (var podCastFile in content.GetValue<ArchetypeModel>("podcastFiles"))
                    {
                        if (!podCastFile.HasValue("image"))
                        {
                            podCastFile.   //What do I do here?
                        }
                    }
    
                    content.SetValue(WHAT-DO-I-DO-HERE, defaultValues.GetProperty("defaultPodCastImage").Value); //And Here
                    sender.Save(content);
                }
    
    
            }
    

    }

  • mrquan1506 9 posts 91 karma points
    Jul 13, 2018 @ 01:29
    mrquan1506
    0

    I have the same problem with you. Have you solve it ? Can you share me a tip ?

Please Sign in or register to post replies

Write your reply to:

Draft