Click here to Skip to main content
15,908,115 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
protected void btnadd_click(object sender, EventArgs e) // Event for adding username and userrole
{
int cnt = 0;
IManageUserRole imanageuserrole = new ManageUserRoleImplementation();
ManageUserRole manageuserrole = new ManageUserRole();
//manageuserrole.userName = txtUserName.Text;
//CommonService abc = new CommonService();
//List<activedirectoryuser> list = new List<activedirectoryuser>();
//list = abc.GetAllADFilterByName(txtUserName.Text);
ActiveDirectoryUtility abc = new ActiveDirectoryUtility();
List<activedirectoryuser> list = new List<activedirectoryuser>();

list = abc.GetUserName(txtUserName.Text);

var ss = from dd in list
where dd.emailId == txtUserName.Text
select dd.emailId;

foreach (var s in list)
{
if (s.userId == txtUserName.Text)
{
cnt++;
}
}
if (cnt == 0)
{
Message.ShowInfoMessage("Invalid UserName");
}


manageuserrole.userRole = ddlselectrole.Text;
manageuserrole.isActive = "TRUE";
manageuserrole.createdDate = DateTime.Now;
manageuserrole.createdByUser = Utility.GetCurrentUserEmail();
manageuserrole.lastUpdatedDate = DateTime.Now;

try
{
string status = imanageuserrole.InsertManageUserRole(manageuserrole);
Message.ShowInfoMessage(status);
//ClientScript.RegisterClientScriptBlock(GetType(), "Javascript", "<script>alert(' "+status+" ')</script>");
BindManageUserRoleGrid();
}
catch
{
Message.ShowInfoMessage("Records Not Added");
//ClientScript.RegisterClientScriptBlock(GetType(), "Javascript", "<script>alert('Records not Added')</script>");



}
}
this is my code
Posted
Comments
johannesnestler 11-Feb-14 8:52am    
I don't understand what's your Problem, can you try to explain it better? It would help if you would take more care in naming your identifiers. Variable-names like abc, s, ss are not "good" and a method which returns a list shouldn't be named GetUserName (better would be GetAllUserNames, GetUserNames, whatever). If you allow me a guess - in the end you will find out that a "mind-bug" was the problem, most likely from wrong naming which led to wrong "symbol-handling" in your brain. ;-)
ZurdoDev 11-Feb-14 9:32am    
Debug the code and let us know what the problem is.
Member 10546331 12-Feb-14 0:01am    
the problem is even after entering valid user those are in activedirectory it is showing invalid username and in list count is equal to 0 which should be equal to 1.
ZurdoDev 12-Feb-14 6:54am    
But you have to debug it and find out why. We can't run your code for you. Step into the code, don't just look at the return values.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900