public static List <ATTUserRoles> GetLSTUserRoles(DataTable tbl) { List <ATTUserRoles> UserRoleLST = new List <ATTUserRoles>(); try { foreach (DataRow row in tbl.Rows) { ATTUserRoles UserObj = new ATTUserRoles ( row["Username"].ToString(), int.Parse(row["RoleID"].ToString()), row["FromDate"].ToString(), row["ToDate"].ToString(), int.Parse(row["ApplID"].ToString()), row["Action"].ToString() ); UserRoleLST.Add(UserObj); } return(UserRoleLST); } catch (Exception ex) { throw ex; } }
public static List <ATTUserRoles> GetUserRoleList(DataTable tbl) { List <ATTUserRoles> UserRoleLST = new List <ATTUserRoles>(); try { foreach (DataRow row in tbl.Rows) { ATTUserRoles UserObj = new ATTUserRoles ( (string)row["USER_NAME"], int.Parse(row["ROLE_ID"].ToString()), (string )row["FROM_DATE"].ToString(), "", int.Parse(row["APPL_ID"].ToString()), "E" ); UserObj.ObjRoles = new ATTRoles ( int.Parse(row["ROLE_ID"].ToString()), int.Parse(row["APPL_ID"].ToString()), (string)row["ROLE_NAME"], (string)row["ROLE_DESCRIPTION"], "E" ); UserObj.ObjApplications = new ATTApplication ( int.Parse(row["APPL_ID"].ToString()), (string)row["APPL_SHORT_NAME"].ToString(), (string)row["APPL_FULL_NAME"].ToString(), (string)row["DESCRIPTION"].ToString(), "E" ); UserRoleLST.Add(UserObj); } return(UserRoleLST); } catch (Exception ex) { throw ex; } }
protected void btn_Save_Click(object sender, EventArgs e) { try { if (lstUsers.SelectedIndex == -1) { List <ATTUsers> lstAllUsers = (List <ATTUsers>)Session["AllUsers"]; ATTUsers objUser = lstAllUsers.Find ( delegate(ATTUsers usr) { return(usr.Username == this.txtUserName_RQD.Text.Trim()); } ); if (objUser != null) { this.lblStatusMessage.Text = "User Already Exists....."; this.programmaticModalPopup.Show(); return; } } if (IsUserValid() == false) { return; } ATTOrganizationUsers objOrgUser; if (DDLTransferTo.SelectedIndex == 0) { objOrgUser = new ATTOrganizationUsers ( (DDLTransferTo.SelectedIndex == 0) ? int.Parse(this.DDLOgranization.SelectedValue) : int.Parse(this.DDLTransferTo.SelectedValue), txtUserName_RQD.Text, "", "", (lstUsers.SelectedIndex != -1) ? "E" : "A" ); } else { objOrgUser = new ATTOrganizationUsers ( (DDLTransferTo.SelectedIndex == -1) ? int.Parse(this.DDLOgranization.SelectedValue) : int.Parse(this.DDLTransferTo.SelectedValue), txtUserName_RQD.Text, "", "", "A" ); } string ActvnSts; if (DDLTransferTo.SelectedIndex > 0) { ActvnSts = "N"; } else { ActvnSts = (chkActive.Checked == true) ? "Y" : "N"; } objOrgUser.ObjUsers = new ATTUsers ( this.txtUserName_RQD.Text, this.txtPassword_RQD.Text, this.txtRePassword_RQD.Text, ((ATTUserLogin)Session["Login_User_Detail"]).UserName, DateTime.Now, DateTime.Parse(this.txtValidUpto_REDT.Text), ActvnSts, (lstUsers.SelectedIndex != -1) ? "E" : "A", (this.txtPersonID.Text == "")?0:double.Parse(this.txtPersonID.Text) ); objOrgUser.LSTUserRoles = BLLUserRoles.GetLSTUserRoles(AddUserRoles()); if (BLLOrganizationUsers.AddOrgUser(objOrgUser) == true) { if (lstUsers.SelectedIndex != -1) { List <ATTOrganization> lstOrganization = (List <ATTOrganization>)Session["Organization"]; List <ATTOrganizationUsers> lstOrgUser = lstOrganization[this.DDLOgranization.SelectedIndex].LSTOrgUsers; if (DDLTransferTo.SelectedIndex == 0) { //EDITS THE LIST AFTER UPDATE IN THE DATABASE lstOrgUser[lstUsers.SelectedIndex].ObjUsers = new ATTUsers ( this.txtUserName_RQD.Text, this.txtPassword_RQD.Text, this.txtRePassword_RQD.Text, ((ATTUserLogin)Session["Login_User_Detail"]).UserName, DateTime.Now, DateTime.Parse(txtValidUpto_REDT.Text), (chkActive.Checked == true) ? "Y" : "N", "E", (this.txtPersonID.Text == "") ? 0 :double.Parse(this.txtPersonID.Text) ); lstOrgUser[lstUsers.SelectedIndex].LSTUserRoles.Clear(); foreach (GridViewRow gvRow in grdRoles.Rows) { if (gvRow.Cells[5].Text != "R") { ATTUserRoles objUserRoles = new ATTUserRoles ( txtUserName_RQD.Text, int.Parse(gvRow.Cells[0].Text), (gvRow.Cells[4].Text != " ") ? gvRow.Cells[4].Text : (string)Session["NepDate"], "", int.Parse(gvRow.Cells[2].Text), "E" ); objUserRoles.ObjRoles = new ATTRoles ( int.Parse(gvRow.Cells[0].Text), int.Parse(gvRow.Cells[2].Text), (string)gvRow.Cells[1].Text, "", "E" ); objUserRoles.ObjApplications = new ATTApplication ( int.Parse(gvRow.Cells[2].Text), "", gvRow.Cells[3].Text, "", "E" ); lstOrgUser[lstUsers.SelectedIndex].LSTUserRoles.Add(objUserRoles); } } } else if (DDLTransferTo.SelectedIndex > 0) { //TRANSFER TO OTHER ORGANIZATION lstOrgUser[lstUsers.SelectedIndex].LSTUserRoles.Clear(); lstOrgUser.RemoveAt(lstUsers.SelectedIndex); //BINDS NEW USERLIST this.lstUsers.DataSource = lstOrgUser; this.lstUsers.DataTextField = "Username"; this.lstUsers.DataValueField = "Username"; this.lstUsers.DataBind(); } } else { //ADDS THE NEW USER IN THE LIST List <ATTOrganization> lstOrganization = (List <ATTOrganization>)Session["Organization"]; List <ATTOrganizationUsers> lstOrgUser = lstOrganization[this.DDLOgranization.SelectedIndex].LSTOrgUsers; List <ATTUserRoles> lstUserRoles = new List <ATTUserRoles>(); foreach (GridViewRow gvRow in grdRoles.Rows) { if (gvRow.Cells[5].Text != "R") { ATTUserRoles objUserRoles = new ATTUserRoles ( txtUserName_RQD.Text, int.Parse(gvRow.Cells[0].Text), (string)Session["NepDate"], "", int.Parse(gvRow.Cells[2].Text), "E" ); objUserRoles.ObjRoles = new ATTRoles ( int.Parse(gvRow.Cells[0].Text), int.Parse(gvRow.Cells[2].Text), (string)gvRow.Cells[1].Text, "", "E" ); objUserRoles.ObjApplications = new ATTApplication ( int.Parse(gvRow.Cells[2].Text), "", gvRow.Cells[3].Text, "", "E" ); lstUserRoles.Add(objUserRoles); } } ATTOrganizationUsers objOrgUsers = new ATTOrganizationUsers( int.Parse(DDLOgranization.SelectedValue), txtUserName_RQD.Text, "", "", "E" ); objOrgUser.LSTUserRoles = lstUserRoles; objOrgUser.ObjUsers = new ATTUsers ( txtUserName_RQD.Text, txtPassword_RQD.Text, txtRePassword_RQD.Text, ((ATTUserLogin)Session["Login_User_Detail"]).UserName, DateTime.Now, DateTime.Parse(txtValidUpto_REDT.Text), (chkActive.Checked == true) ? "Y" : "N", "E", (this.txtPersonID.Text == "") ? 0 :double.Parse(this.txtPersonID.Text) ); lstOrgUser.Add(objOrgUser); this.lstUsers.DataSource = lstOrgUser; this.lstUsers.DataTextField = "Username"; this.lstUsers.DataValueField = "Username"; this.lstUsers.DataBind(); } txtUserName_RQD.Enabled = true; ClearContros(); } } catch (Exception ex) { this.lblStatusMessage.Text = "<CENTER>Error In Saving User..</CENTER><BR><BR>" + ex.ToString(); this.programmaticModalPopup.Show(); } }