November Happy Hour will be moved to Thursday December 5th.

Using IValidate on CatalogEvent_RelationUpdating

Vote:
 

Im want to display error message to UI when user change the quantity of package entry.

Im firgured out has a way to validate data of CatalogRelationDto by using ICatalogEvents like this:

public void Initialize(InitializationEngine context)
{
	var catalogEvent = ServiceLocator.Current.GetInstance<ICatalogEvents>();
	catalogEvent.RelationUpdating += CatalogEvent_RelationUpdating;
}


private void CatalogEvent_RelationUpdating(object sender, RelationEventArgs e)
{
	if (sender is CatalogRelationDto)
	{
		// TODO: Validate data
		// TODO: Show error message
	}
}

But currently im have no idear to show error message to UI like IValidate behavior.

Does any one have some idear?

Thanks alot.

#307457
Aug 25, 2023 8:04
Vote:
 

I don't think you can use IValidate here, but throwing an exception would halt the operation. maybe not as nice as a warning, but should still work

this 

            var dto = sender as CatalogRelationDto;
            if (dto.CatalogEntryRelation.Any(x => x.RowState != System.Data.DataRowState.Unchanged))
            {
                throw new InvalidOperationException("this can be done");
            }

would show this

#307460
Edited, Aug 25, 2023 10:03
MrSuro - Aug 25, 2023 11:01
Thanks for your support,

Im already try this solution before.
But with any type of exeption, the response allway 400 and no UI effect was applied.

Im on editing of "Edit Package" page, for edit entry items.
Quan Mai - Aug 28, 2023 5:57
it works for the product-variant screen. it is quite the same with package entries. not sure what is different
Vote:
 

For request Add Package Entries (variants or packages), it worked if we throw exception from ICatalogEvents, but not for delete/update request.

I don't know the difference.

#307576
Aug 28, 2023 7:41
* 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.