Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Joshua Genato 3 posts 73 karma points
    Apr 05, 2019 @ 02:13
    Joshua Genato
    0

    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;
            }    
    
Please Sign in or register to post replies

Write your reply to:

Draft