Create User Group - SavingUserGroup cancel saving not working
When creating a new groups under users section, I tried to override the SavingUserGroup to validate if the group name contains invalid character, but the e.cancel is not working when set to true.
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
UserService.SavingUserGroup += SavingUserGroup_Saving;
}
private void SavingUserGroup_Saving(IUserService sender, SaveEventArgs<IUserGroup> e)
{
try
{
string InvalidInputMsg = "The changes made contains an invalid character: {0}";
InputValidator validate = new InputValidator();
foreach (var group in e.SavedEntities)
{
if (group != null)
{
if (!validate.ValidateCharacters(group.Name, UMBDataType.GroupName))
{
throw new Exception(string.Format(InvalidInputMsg, "Group Name"));
}
}
}
}
catch (Exception ex)
{
e.Messages.Add(new EventMessage("Error", ex.Message, EventMessageType.Error));
e.Cancel = true;
}
Create User Group - SavingUserGroup cancel saving not working
When creating a new groups under users section, I tried to override the SavingUserGroup to validate if the group name contains invalid character, but the e.cancel is not working when set to true.
is working on a reply...