public async Task <UpdateStatusEnum> UpdateItemAsync(UserDefinition data)
        {
            CleanupRoles(data);

            if (data.UserId == SuperuserDefinitionDataProvider.SuperUserId || string.Compare(data.UserName, SuperuserDefinitionDataProvider.SuperUserName, true) == 0)
            {
                using (SuperuserDefinitionDataProvider superDP = new SuperuserDefinitionDataProvider()) {
                    return(await superDP.UpdateItemAsync(data));
                }
            }
            return(await UpdateItemAsync(data.UserName, data));
        }
        public async Task <UpdateStatusEnum> UpdateItemAsync(string originalName, UserDefinition data)
        {
            CleanupRoles(data);

            if (!Manager.HasSuperUserRole)
            {
                int superuserRole = Resource.ResourceAccess.GetSuperuserRoleId();
                if (data.RolesList.Contains(new Role {
                    RoleId = superuserRole
                }, new RoleComparer()))
                {
                    // new data has super user role
                    // get original to make sure superuser role isn't new
                    UserDefinition origData = await GetItemByUserIdAsync(data.UserId);

                    if (!origData.RolesList.Contains(new Role {
                        RoleId = superuserRole
                    }, new RoleComparer()))
                    {
                        throw new Error(this.__ResStr("noSup", "Only a superuser can assign superuser status to another user"));
                    }
                }
            }

            if (string.Compare(data.UserName, SuperuserDefinitionDataProvider.SuperUserName, true) == 0 &&
                string.Compare(originalName, SuperuserDefinitionDataProvider.SuperUserName, true) != 0)
            {
                return(UpdateStatusEnum.NewKeyExists);
            }
            if (string.Compare(originalName, SuperuserDefinitionDataProvider.SuperUserName, true) == 0)
            {
                if (data.UserName != originalName)
                {
                    throw new Error(this.__ResStr("cantRenameSuper", "The user \"{0}\" can't be renamed.", originalName));
                }
                using (SuperuserDefinitionDataProvider superDP = new SuperuserDefinitionDataProvider()) {
                    return(await superDP.UpdateItemAsync(data));
                }
            }
            UserDefinition origUser = Auditing.Active ? await GetItemAsync(originalName) : null;

            UpdateStatusEnum result = await DataProvider.UpdateAsync(originalName, data.UserName, data);

            await Auditing.AddAuditAsync($"{nameof(UserDefinitionDataProvider)}.{nameof(UpdateItemAsync)}", originalName, Guid.Empty,
                                         "Update User",
                                         DataBefore : origUser,
                                         DataAfter : data
                                         );

            return(result);
        }