Error occurs when you add userdata with same display name or username as a deleted user

  • Updated

Using the API, when you add membership users (with the same username and display name) that were previoulsy deleted from the CMS, an error occurs.

ErrorAddingName

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
protected void uxSubmit_Click(object sender, EventArgs e)
    {
        //instantiated the user manager constructor
        Ektron.Cms.Framework.User.UserManager uManager = new Ektron.Cms.Framework.User.UserManager(Ektron.Cms.Framework.ApiAccessMode.Admin);
        //Filling up the user data object before adding. This is to mimic the user data add that will be done.  
        Ektron.Cms.UserData uData = new Ektron.Cms.UserData();
        uData.Username = "1@1.com";
        uData.FirstName = "Ben";
        uData.LastName = "Smith";
        uData.Password = "qwerty123";
        uData.Email = "test@test.com";
        uData.DisplayName = "testDisplayName1";
        uData.Address = "1243 Test Addresss Nashua, NH 03063";
        uData.IsMemberShip = true;
      
        uData.CustomProperties = uManager.GetCustomPropertyList();
        uData.CustomProperties["Time Zone"].Value = "Central Standard Time";
        uData.CustomProperties["Private Profile"].Value = "Public";
        uData.CustomProperties["Phone"].Value = "603-333-3333";

        //Creates criteria filter groups
        //Checks to see if the users is deleted
        //Also checks of those deleted users if their display or username is the same as the  
        //user data that we are looking to add to the CMS.  
        Ektron.Cms.Common.CriteriaFilterGroup<Ektron.Cms.User.UserProperty> filterGroup1 = new Ektron.Cms.Common.CriteriaFilterGroup<Ektron.Cms.User.UserProperty>();
        filterGroup1.AddFilter(Ektron.Cms.User.UserProperty.IsDeleted, Ektron.Cms.Common.CriteriaFilterOperator.EqualTo, true);
        filterGroup1.AddFilter(Ektron.Cms.User.UserProperty.DisplayName, Ektron.Cms.Common.CriteriaFilterOperator.EqualTo, uData.DisplayName);

        Ektron.Cms.Common.CriteriaFilterGroup<Ektron.Cms.User.UserProperty> filterGroup2 = new Ektron.Cms.Common.CriteriaFilterGroup<Ektron.Cms.User.UserProperty>();
        filterGroup2.AddFilter(Ektron.Cms.User.UserProperty.IsDeleted, Ektron.Cms.Common.CriteriaFilterOperator.EqualTo, true);
        filterGroup2.AddFilter(Ektron.Cms.User.UserProperty.UserName, Ektron.Cms.Common.CriteriaFilterOperator.EqualTo, uData.Username);

        //creates new user criteria object
        Ektron.Cms.User.UserCriteria criteria = new Ektron.Cms.User.UserCriteria();
        criteria.FilterGroups.Add(filterGroup1);
        criteria.Condition = Ektron.Cms.Common.LogicalOperation.Or;
        criteria.FilterGroups.Add(filterGroup2);
        // allows for up to 10000 users
        criteria.PagingInfo = new Ektron.Cms.PagingInfo(10000);
        //returns users
        List<Ektron.Cms.UserData> userList = uManager.GetList(criteria);

        if (userList.Count != 0)
        {             
            //iterates over the list and adds a string value to the user name
            foreach (var i in userList)
            {
                int counter = 0;
                i.Username = i.Username + counter.ToString();
                i.DisplayName = i.DisplayName + counter.ToString();
                uManager.Update(i);
                counter++;
            }
        }
        uManager.Add(uData);

    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div class="clearfix">
        <ektronUI:Button ID="uxSubmit" runat="server" OnClick="uxSubmit_Click" Text="Check Username And Add User" Visible="true"></ektronUI:Button>
        <ektronUI:Label ID="uxRequiredLabel" CssClass="span-4" runat="server" />
    </div>
    </form>
</body>
</html>