Using IValidate to show info to user - Commerce 9

Vote:
 

Hi

I will like to show in to user that are trying to delete a node with some entries in it.

I am using CatalogEventListnerBase. Is there any way to show the info? 

I was trying to use IValidate, as belog, but did not fire...

	public class CommerceNodeValidator : IValidate
	{
		readonly IContentRepositoryEpiAbstraction _contentRepositoryEpiAbstraction;

		public CommerceNodeValidator(IContentRepositoryEpiAbstraction contentRepositoryEpiAbstraction)
		{
			_contentRepositoryEpiAbstraction = contentRepositoryEpiAbstraction;
		}

		public IEnumerable Validate(BaseCategoryNode instance)
		{
			var decendentEntries = _contentRepositoryEpiAbstraction.GetDescendents(instance.ContentLink.ToPageReference());

			if (!decendentEntries.Any())
				return Enumerable.Empty();

			ValidationError[] validationError = 
			{
				new ValidationError
				{
					ErrorMessage = "You cannot delete this node",
					PropertyName = "CategoryNode",
					Severity = ValidationErrorSeverity.Error,
					ValidationType = ValidationErrorType.AttributeMatched
				}
			};

			return validationError;

		}
	}
#144688
Feb 17, 2016 13:14
Vote:
 

Hi

IValidate is not called on delete, it's only called on save. If you want to have your code execute at delete from the UI you should attach it to IContentEvents. If you attach to DeletingContent you should be able to cancel the deletion, although I'm not sure if that is enough for your needs.

Regards

Per Gunsarfs

#144692
Feb 17, 2016 13:46
Vote:
 

Might be moving content as well. Not sure if deleting trigger of moving to wastebasket. Didn't earlier at least..

#144696
Feb 17, 2016 14:32
Vote:
 

For moving content, even to the wastebasket, MovingContent and MovedContent will be raised.

Note that there is no wastebasket concept for catalog content. (You can only delete them, which raises DeletingContent and DeletedContent)

Perhaps listening to those events will be enough.

/Q

#144704
Feb 17, 2016 16:16
Vote:
 

@Quan

I was using EntryUpdating in CatalogEventListenerBase and I am trying to catch RowState => Deleted. But the CatalogEntryDto are null, is very strainge.

How do I use DeletingContent? DeletedContent?

there is not in CatalogEventListenerBase... 

Its must fire when I Delete a Entry(Variation, product...) or Node

#144706
Feb 17, 2016 16:54
Vote:
 

Hi.

Those events are in IContentEvents. You can pass it to your class constructor (as a constructor dependency) and use it there  

http://world.episerver.com/documentation/class-library/?documentId=cms/7/306eae4b-2ba2-dd1e-c114-bccb0d3d2968

/Q

#144707
Feb 17, 2016 17:11
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.