Keep getting this error

Error: CS0104 - line 299 (2631) - ‘UserFileAdapter’ is an ambiguous reference between ‘Erp.Adapters.UserFileAdapter’ and ‘Ice.Adapters.UserFileAdapter’

indent preformatted text by 4 spaces

Blockquote
private bool CheckUserIdSecGrp()
{
// Get the Current User ID from the Call Context Client data set.
EpiDataView edv = (EpiDataView) this.oTrans.EpiDataViews[“CallContextClientData”];
string myuser = edv.dataView[0][“CurrentUserId”].ToString();
try
{ //need to bring in UserFileAdapter as well via import bl assemblies to get this reference
UserFileAdapter adapterUserFile = new UserFileAdapter(this.oTrans);

		        adapterUserFile.BOConnect();
    		    bool result = adapterUserFile.GetByID(myuser); 
				// Get the dataset by the login User session id. GetByID. Returns a Dataset given the primary key. 
        		if (result == true)
        		{
            		if (adapterUserFile.UserFileData.UserFile[0]["GroupList"].ToString().IndexOf("CountCycleFull") != -1) // The security group name (code id). 
		            {
						return true; // fullVersion = true lets you see the full menu.
					}
        		}
        // Cleanup Adapter Reference
        adapterUserFile.Dispose();
    		}
    	catch (System.Exception ex)
    		{
        		ExceptionBox.Show(ex);
    		}
		return false; //fullVersion = false hides part of the menu.
	}

Try making it unambiguous by defining the type you’re trying to use by defining the full assembly in the adapter reference.

There both an Erp and Ice version of this. In my (really brief) testing either object returns the same data for GetByID, you just need to fully declare the namespace.
The ice version has additional methods available(IsPasswordExpired(), IsUserNameAvailable(), …)

You’ll need to either remove one of the references(ice or erp), if possible or fully declare the namespace, something like this.

Erp.Contracts.UserFileAdapter adapterUserFile = new Erp.Contracts.UserFileAdapter(this.oTrans);
1 Like

Thanks that worked.

That is actually working like I want it to but I would like to check for a list of Security Groups. If it is any one of a list of security codes.

The GroupList field provides a tilde delimited list of security group codes the user is authorized for.

this is what i have for evaluated code now.

Blockquote
private bool CheckUserIdSecGrp()
{
// Get the Current User ID from the Call Context Client data set.
EpiDataView edv = (EpiDataView) this.oTrans.EpiDataViews[“CallContextClientData”];
//required Security Groups to duplicate Quotes
string secGroups = “ENGR-GEN,ENGR-SUPR,MFG-ENGR,MFG-MGR,OPS-DIR,IT-ADMIN”;
string myuser = edv.dataView[0][“CurrentUserId”].ToString();
try
{ //need to bring in UserFileAdapter as well via import bl assemblies to get this reference
Ice.Adapters.UserFileAdapter adapterUserFile = new Ice.Adapters.UserFileAdapter(this.oTrans);

		        adapterUserFile.BOConnect();
    		    bool result = adapterUserFile.GetByID(myuser); 
				// Get the dataset by the login User session id. GetByID. Returns a Dataset given the primary key. 
        		if (result == true)
        		{
					if (adapterUserFile.UserFileData.UserFile[0]["GroupList"].ToString().IndexOf(secGroups) != -1) // The security group name (code id). 
		            {
						return true; // fullVersion = true lets you see the full menu.
					}
        		}
        // Cleanup Adapter Reference
        adapterUserFile.Dispose();
    		}
    	catch (System.Exception ex)
    		{
        		ExceptionBox.Show(ex);
    		}
		return false; //fullVersion = false hides part of the menu.
	}

I think this approach will only work if the requirement is that users are part of all of the security groups and furthermore, they would need to be added in same order as the list of required groups(comparing the entire delimited string).
I am assuming users should have full access to the menu if they are part of any of the sec groups. If so, you will need to split the user’s group list value up by the tilde characters. Then loop over the results of the split to see if any single user sec group string is contained in your list of approved sec groups.
You still run the risk of sec group id overlap, for example if one of the permitted group ids is ‘IT-ADMIN’ and the user belongs to a group id of ‘IT’, checking for the user existence using IndexOf would return true.
To be really safe break them both up into string arrays, loop over each and compare, something like this:

string[] secGrps = secGroups.Split(',');
string[] userGrps = adapterUserFile.UserFileData.UserFile[0]["GroupList"].Split('~');
bool approved = false;
bool outerBreak = false;
foreach(string userGrpStr in userGrps)
{
    foreach(string secGrpStr in secGrps)
    {
        if(secGrpStr == userGrpStr)
        {
            approved = true;
            outerBreak = true;
            break;
        }
    }
    if(outerBreak)
        break;
}

You could use Intersect once you have two arrays, but I think most of the benefit is just syntactic sugar, which can still be pretty sweet, no need to see the nested foreach loops :slight_smile: :

var inter = secGrps.Intersect(myGrps, StringComparer.Ordinal);
bool approved = inter.Count() > 0;

if you are going to go that far, you could make it even simpler:

bool approved = secGrps.Intersect(myGrps, StringComparer.Ordinal).Count()>0;

the following MIGHT work too, and if it does, it is theoretically quicker since it doesn’t have to actually count how many exist. It will stop after it finds one.

bool approved = secGrps.Intersect(myGrps, StringComparer.Ordinal).Any();