Enforce Unique ID field for content item
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?
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