1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Enforce Unique ID field for content item

Enforce Unique ID field for content item

2 posts, 0 answered
  1. Rico
    Rico avatar
    88 posts
    Registered:
    30 Aug 2012
    22 Mar 2013
    Link to this post
    Is there way to enforce a field to be 'unique'. I have a requirement where I have a 'Projects' module. Each content item will have a 'ProjectID'. I want to enforce uniqueness of this field; however the field is manually entered via the UI by the user (cannot be a GUID). Example: ProjectID = 123-33-4. Prior to having the item created, I would like to check that there is no pre-existing project in the system with that same ProjectID. I can't seem to find where/how this can be done...
    I thought perhaps there would be an event I could tap into to do a query, but there doesn't appear to be one...
    there is no 'IDynamicContentCreatingEvent' that triggers ahead of time that the actual item is created
    , there's only the 'created' event...
    EventHub.Subscribe<IDynamicContentCreatedEvent>(evt => CRD.Sitefinity.CustomDecorator.BusinessOpportunitiesDecorator.ContentCreatedEventHandler(evt));

    Ideas?
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    16 Aug 2017
    27 Mar 2013
    Link to this post
    Hello Rico,

    You can use the OpenAccess provider implementation which would allow you to subscribe to the Manager.Executing event which gets fired prior to committing the transaction:
    protected void Application_Start(object sender, EventArgs e)
            {
                Bootstrapper.Initialized += Bootstrapper_Initialized;
            }
     
            void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
            {
                DynamicModuleManager.Executing += new EventHandler<ExecutingEventArgs>(DyamicContentProvider_Executing);
            }
     
            protected void DyamicContentProvider_Executing(object sender, ExecutingEventArgs args)
            {
                if (!(args.CommandName == "CommitTransaction" || args.CommandName == "FlushTransaction"))
                    return;
                var provider = sender as DynamicModuleDataProvider;
                foreach (var item in provider.GetDirtyItems())
                {
                    SecurityConstants.TransactionActionType itemStatus = provider.GetDirtyItemStatus(item);
                    if (itemStatus == SecurityConstants.TransactionActionType.New || itemStatus == SecurityConstants.TransactionActionType.Updated)
                    {
                        if (item is DynamicContent)
                        {
                            //do something here
                        }
                    }
                }
            }




    Regards,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered