Copied to clipboard

Flag this post as spam?

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


  • Naor C 8 posts 107 karma points
    6 days ago
    Naor C
    0

    [Umbraco 10] Getting edited value before saving

    Hello. I am building a "terms of use" page using Umbraco 10 and I have 2 properties: Description and Version. I want to write the following verification: if someone has changed the Description then he should raise the version by atleast 1.

    So I have a verification handler, whenever someone is pressing "save" I will go through all the properties and check that all of them are valid.

    When I'm trying to validate the TermsOfUse page I'm not getting the old value of the property I have changed, just the new one. This is my code:

    IContent termsOfUsePage = ContentService.GetRootContent().FirstOrDefault(x => x.Name == "TermsOfUse");
    var currentDescriptions = termsOfUsePage.Properties.FirstOrDefault(n => n.Alias == "Description").Values.ToArray();
    var currentVersions = termsOfUsePage.Properties.FirstOrDefault(n => n.Alias == "version").Values.ToArray();
    
    var version = currentVersions.Where(p => p.Culture == culture).FirstOrDefault();
    var description = currentDescriptions.Where(p => p.Culture == culture).FirstOrDefault();
    if(description != null && version != null)
    {
    
        if (description.PublishedValue.ToString() != description.EditedValue.ToString())
        {
            if (int.Parse(version.EditedValue.ToString()) <= int.Parse(version.PublishedValue.ToString()))
            {
                throw new Exception("Can't change description and keep old version! ");
            }
        }
    }
    

    What am I doing wrong? How can I get both old version/description and new version/description?

    Thanks in advance!

Please Sign in or register to post replies

Write your reply to:

Draft