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.


<%@ 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 = "";
        uData.FirstName = "Ben";
        uData.LastName = "Smith";
        uData.Password = "qwerty123";
        uData.Email = "";
        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.Condition = Ektron.Cms.Common.LogicalOperation.Or;
        // 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();



<html xmlns="">
<head id="Head1" runat="server">
    <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" />