public UpdateADUserResponse UpdateADUser(UpdateADUserRequest req) { UpdateADUserResponse resp = new UpdateADUserResponse(); resp.hdr = new RespHdr(); resp.hdr.Successful = true; return(resp); }
protected void btnSave_Click(object sender, EventArgs e) { Model.Users userInfo = UsersManager.GetModel(CurrUser.iUserID); Model.UserPipelineColumns userPipelineCols = UserPipelineColsManager.GetModel(CurrUser.iUserID); Model.UserProspectColumns userProspectCols = UserProspectColsManager.GetModel(CurrUser.iUserID); Model.UserHomePref userHomePref = UserHomePrefManager.GetModel(CurrUser.iUserID); try { if (null == userInfo) { LPLog.LogMessage(LogType.Logerror, string.Format("User Personalization: User with id {0} does not exist.", CurrUser.iUserID)); ClientFun("unknowerrmsg2", "ShowMsg('unknowerror');"); return; } if (!GetUserInfo(ref userInfo)) { ClientFun("invalidinputmsg", "ShowMsg('invalidInput');"); return; } UsersManager.Update(userInfo); if (null == userPipelineCols) { userPipelineCols = new Model.UserPipelineColumns(); userPipelineCols.UserId = CurrUser.iUserID; GetUserPipelineColumnsInfo(ref userPipelineCols); UserPipelineColsManager.Add(userPipelineCols); } else { GetUserPipelineColumnsInfo(ref userPipelineCols); UserPipelineColsManager.Update(userPipelineCols); } if (null == userProspectCols) { userProspectCols = new Model.UserProspectColumns(); userProspectCols.UserId = CurrUser.iUserID; GetUserProspectColumnsInfo(ref userProspectCols); UserProspectColsManager.Add(userProspectCols); } else { GetUserProspectColumnsInfo(ref userProspectCols); UserProspectColsManager.Update(userProspectCols); } if (null == userHomePref) { userHomePref = new Model.UserHomePref(); userHomePref.UserId = CurrUser.iUserID; GetUserHomePrefInfo(ref userHomePref); UserHomePrefManager.Add(userHomePref); } else { GetUserHomePrefInfo(ref userHomePref); UserHomePrefManager.Update(userHomePref); } if (!string.IsNullOrEmpty(this.tbPWD.Text)) { try { ServiceManager sm = new ServiceManager(); using (LP2ServiceClient service = sm.StartServiceClient()) { ReqHdr hdr; UpdateADUserRequest uReq = new UpdateADUserRequest(); hdr = new ReqHdr(); hdr.UserId = CurrUser.iUserID; uReq.hdr = hdr; uReq.Command = UserMgrCommandType.ChangePassword; uReq.AD_OU_Filter = this.hiPrefix.Value; uReq.AD_User = new LP_Service.User(); uReq.AD_User.Password = this.tbPWD.Text; uReq.AD_User.Username = this.hiUsername.Value; uReq.AD_User.Firstname = this.hiFirstName.Value; uReq.AD_User.Lastname = this.hiLastName.Value; uReq.AD_User.Email = this.lbEmail.Text; UpdateADUserResponse uResponse; uResponse = service.UpdateADUser(uReq); if (!uResponse.hdr.Successful) { PageCommon.AlertMsg(this, "Failed to change password in AD, error info: " + uResponse.hdr.StatusInfo); LPLog.LogMessage(LogType.Logerror, "Failed to change password in AD, username="******"Failed to change password in AD, reason: User Manager is not running."); return; } catch (Exception ex) { PageCommon.AlertMsg(this, "Failed to change password in AD, exception info: " + ex.Message); LPLog.LogMessage(LogType.Logerror, "Failed to change password in AD, username="******", Exception:" + ex.Message); return; } } ClientFun("sucsmsg", "ShowMsg('savesuccess');"); } catch (Exception ex) { PageCommon.AlertMsg(this, "Failed to save user personalization info, reason:" + ex.Message); LPLog.LogMessage(LogType.Logerror, "Failed to save user personalization info: " + ex.Message); return; } }
/// <summary> /// Save user info /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { Model.Users newUser = null; if ("0" == Mode) { newUser = new Model.Users(); if (GetValue(ref newUser)) { //set the new user's default loans per page(50) newUser.LoansPerPage = 50; if (!CheckBeforeSave(newUser)) { return; } int?nSourceUID = null; int nTemp = 0; if (null != ViewState["SourceUID"]) { if (int.TryParse(ViewState["SourceUID"].ToString(), out nTemp)) { nSourceUID = nTemp; } } try { // save the new added user info, nSourceUID is null or not indicated to clone or not UserId = UsersManager.AddUserInfo(newUser, this.hiCurrLoanRep.Value, this.hiCurrGroup.Value, nSourceUID); Mode = "1"; this.btnDelete.Enabled = true; this.btnClone.Enabled = true; try { ServiceManager sm = new ServiceManager(); using (LP2ServiceClient service = sm.StartServiceClient()) { UpdateADUserRequest uReq = new UpdateADUserRequest(); ReqHdr hdr = new ReqHdr(); hdr.UserId = UserId.Value; uReq.hdr = hdr; uReq.AD_OU_Filter = this.lbPrefix.Text; uReq.AD_User = new LP_Service.User(); uReq.AD_User.Username = this.tbUserName.Text; uReq.AD_User.Firstname = this.tbFirstName.Text; uReq.AD_User.Lastname = this.tbLastName.Text; uReq.AD_User.Email = this.tbEmail.Text; uReq.AD_User.Enabled = this.ckbEnabled.Checked; if (!string.IsNullOrEmpty(this.tbPWD.Text.Trim())) { uReq.AD_User.Password = this.tbPWD.Text.Trim(); } else { uReq.AD_User.Password = string.Empty; } uReq.Command = UserMgrCommandType.CreateUser; UpdateADUserResponse uResponse; uResponse = service.UpdateADUser(uReq); if (!uResponse.hdr.Successful) { PageCommon.AlertMsg(this, "Failed to save user info in AD."); CallClientFn("closeBox(true);"); LPLog.LogMessage(LogType.Logerror, "Failed to save user info in AD. UserID: " + UserId.ToString() + ", Error: " + uResponse.hdr.StatusInfo); return; } } } catch (System.ServiceModel.EndpointNotFoundException ee) { LPLog.LogMessage(ee.Message); CallClientFn("closeBox(true);"); PageCommon.AlertMsg(this, "Failed to save user info in AD, reason: User Manager is not running."); return; } catch (Exception ex) { PageCommon.AlertMsg(this, "Failed to save user info in AD, reason:" + ex.Message); CallClientFn("closeBox(true);"); LPLog.LogMessage(LogType.Logerror, "Error occured when save user info in AD: " + ex.Message); return; } CallClientFn("ShowMsg('saveSuccss', '', true, true);"); } catch (Exception ex) { PageCommon.AlertMsg(this, "Failed to save user info, reason:" + ex.Message); LPLog.LogMessage(LogType.Logerror, "Error occured when save user info: " + ex.Message); return; } } else { CallClientFn("ShowMsg('invalidInput', '', false);"); } } else if ("1" == Mode) { newUser = UsersManager.GetModel(UserId.Value); bool changePwd = false; if ((newUser.Password != tbPWD.Text.Trim()) && !string.IsNullOrEmpty(tbPWD.Text.Trim())) { changePwd = true; } if (GetValue(ref newUser)) { if (!CheckBeforeSave(newUser)) { return; } try { // update current user info, without personalization info UsersManager.UpdateUserInfo(newUser, this.hiCurrLoanRep.Value, this.hiCurrGroup.Value); try { ServiceManager sm = new ServiceManager(); using (LP2ServiceClient service = sm.StartServiceClient()) { UpdateADUserRequest uReq = new UpdateADUserRequest(); ReqHdr hdr = new ReqHdr(); hdr.UserId = UserId.Value; uReq.hdr = hdr; uReq.AD_OU_Filter = this.lbPrefix.Text; uReq.AD_User = new LP_Service.User(); uReq.AD_User.Username = this.tbUserName.Text; uReq.AD_User.Firstname = this.tbFirstName.Text; uReq.AD_User.Lastname = this.tbLastName.Text; uReq.AD_User.Email = this.tbEmail.Text; uReq.AD_User.Enabled = this.ckbEnabled.Checked; if (changePwd) { uReq.AD_User.Password = this.tbPWD.Text; } else { uReq.AD_User.Password = string.Empty; } uReq.Command = UserMgrCommandType.UpdateUser; UpdateADUserResponse uResponse; uResponse = service.UpdateADUser(uReq); if (!uResponse.hdr.Successful) { PageCommon.AlertMsg(this, "Failed to update user info in AD, reason: " + uResponse.hdr.StatusInfo); CallClientFn("closeBox(true, false);"); LPLog.LogMessage(LogType.Logerror, "Failed to update user info to AD. UserID: " + UserId.ToString() + ", Error: " + uResponse.hdr.StatusInfo); return; } } } catch (System.ServiceModel.EndpointNotFoundException ee) { LPLog.LogMessage(ee.Message); CallClientFn("closeBox(true, false);"); PageCommon.AlertMsg(this, "Failed to update user info in AD, reason: User Manager is not running."); return; } catch (Exception ex) { PageCommon.AlertMsg(this, "Failed to update user info in AD, reason: " + ex.Message); CallClientFn("closeBox(true, false);"); LPLog.LogMessage(LogType.Logerror, "Error occured when update user info to AD: " + ex.Message); return; } CallClientFn("ShowMsg('saveSuccss', '', true, true, false);"); } catch (Exception ex) { PageCommon.AlertMsg(this, "Failed to save user info, reason: " + ex.Message); LPLog.LogMessage(LogType.Logerror, "Failed to save user info: " + ex.Message); return; } } else { CallClientFn("ShowMsg('invalidInput', '', false);"); } } }
/// <summary> /// Delete all user info when click "Delete" button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnDelete_Click(object sender, EventArgs e) { bool bRessignSuccess = false; ServiceManager sm1 = new ServiceManager(); using (LP2ServiceClient service = sm1.StartServiceClient()) { ReassignLoanRequest req = new ReassignLoanRequest(); req.hdr = new ReqHdr(); req.hdr.SecurityToken = "SecurityToken"; //todo:check dummy data req.hdr.UserId = CurrUser.iUserID; // get all loans assigned to this user DataSet dsUserLoan = LoanTeamManager.GetUserLoan(UserId.Value); int nReassignUserId = 0; if (!int.TryParse(this.hiReassignUserId.Value, out nReassignUserId)) { nReassignUserId = 0; } if (null != dsUserLoan && dsUserLoan.Tables.Count > 0 && dsUserLoan.Tables[0].Rows.Count > 0) { List <ReassignUserInfo> uList = new List <ReassignUserInfo>(); Model.Users userToDelete = UsersManager.GetModel(UserId.Value); ReassignUserInfo uInfo = null; foreach (DataRow drUserLoan in dsUserLoan.Tables[0].Rows) { uInfo = new ReassignUserInfo(); uInfo.FileId = int.Parse(string.Format("{0}", drUserLoan["FileId"])); uInfo.RoleId = int.Parse(string.Format("{0}", drUserLoan["RoleId"])); uInfo.NewUserId = nReassignUserId; uList.Add(uInfo); } req.reassignUsers = uList.ToArray(); ReassignLoanResponse respone = null; try { respone = service.ReassignLoan(req); if (respone.hdr.Successful) { bool st = true; int fileId = 0; int newUserId = 0; int roleId = 0; int requester = req.hdr.UserId; foreach (ReassignUserInfo u in req.reassignUsers) { fileId = u.FileId; newUserId = u.NewUserId; roleId = u.RoleId; st = LPWeb.BLL.WorkflowManager.ReassignLoan(fileId, newUserId, UserId.Value, roleId, requester); } bRessignSuccess = true; } else { PageCommon.AlertMsg(this, "Failed to reassign loan, reason:" + respone.hdr.StatusInfo); CloseMe(true, true); return; } } catch (System.ServiceModel.EndpointNotFoundException ex) { LPLog.LogMessage(ex.Message); PageCommon.AlertMsg(this, "Failed to reassign loan, reason: User Manager is not running."); CloseMe(true, true); } catch (Exception exception) { LPLog.LogMessage(exception.Message); PageCommon.AlertMsg(this, string.Format("Failed to reassign loan, reason:{0}.", exception.Message)); CloseMe(true, true); } } else { bRessignSuccess = true; } if (bRessignSuccess) { UsersManager.DeleteUserInfo(UserId.Value, null, null, CurrUser.iUserID, nReassignUserId); LPLog.LogMessage(string.Format("User {0} deleted successfully.", this.tbUserName.Text)); CloseMe(true, true); try { ServiceManager sm = new ServiceManager(); using (LP2ServiceClient service2 = sm.StartServiceClient()) { UpdateADUserRequest uReq = new UpdateADUserRequest(); ReqHdr hdr = new ReqHdr(); hdr.UserId = UserId.Value; uReq.hdr = hdr; uReq.Command = UserMgrCommandType.DeleteUser; uReq.AD_OU_Filter = this.lbPrefix.Text; uReq.AD_User = new LP_Service.User(); uReq.AD_User.Username = this.tbUserName.Text; uReq.AD_User.Firstname = this.tbFirstName.Text; uReq.AD_User.Lastname = this.tbLastName.Text; uReq.AD_User.Email = this.tbEmail.Text; uReq.AD_User.Enabled = this.ckbEnabled.Checked; UpdateADUserResponse uResponse; uResponse = service2.UpdateADUser(uReq); if (!uResponse.hdr.Successful) { PageCommon.AlertMsg(this, "Failed to delete user in AD, reason:" + uResponse.hdr.StatusInfo); LPLog.LogMessage(LogType.Logerror, "Failed to delete user in AD. UserID: " + UserId.ToString()); } } } catch (System.ServiceModel.EndpointNotFoundException ee) { LPLog.LogMessage(ee.Message); PageCommon.AlertMsg(this, "Failed to delete user in AD, reason: User Manager is not running."); } catch (Exception ex) { PageCommon.AlertMsg(this, "Failed to delete user in AD, reason: " + ex.Message); LPLog.LogMessage(LogType.Logerror, "Error occured while trying to delete user in AD: " + ex.Message); } } } }
protected void btnSave_Click(object sender, EventArgs e) { Model.Users userInfo = UsersManager.GetModel(CurrUser.iUserID); try { if (null == userInfo) { LPLog.LogMessage(LogType.Logerror, string.Format("User Personalization - Settings: User with id {0} does not exist.", CurrUser.iUserID)); ClientFun("unknowerrmsg2", "alert('User does not exists, unknow error.');"); return; } if (!GetUserInfo(ref userInfo)) { ClientFun("invalidinputmsg", "alert('Invalid input!');"); return; } if (this.FileUpload1.HasFile) { string strMsg = ""; bool bIsValid = PageCommon.ValidateUpload(this, this.FileUpload1, 1024 * 1024 * 15, out strMsg, ".jpg", ".bmp", ".png", ".gif"); if (!bIsValid) { ClientFun("userPicInvalid", string.Format("alert('{0}');", strMsg)); return; } } string phone = this.txbPhone.Text.Trim(); userInfo.Phone = phone; userInfo.Fax = this.txbFax.Text.Trim(); userInfo.Cell = this.txbCell.Text.Trim(); userInfo.LicenseNumber = this.txbLicense.Text.Trim(); userInfo.NMLS = this.txbNMLS.Text.Trim(); userInfo.ExchangePassword = this.txbExchangPwd.Text.Trim(); if (userInfo.ExchangePassword == "" && !string.IsNullOrEmpty(this.tbPWD.Text)) { userInfo.ExchangePassword = this.tbPWD.Text.Trim(); } UsersManager.Update(userInfo); #region Save as UserLicense gdc CR43 if (!string.IsNullOrEmpty(hidLicenseNumberList.Value.Trim())) { try { List <Model.UserLicenses> ulList = new List <Model.UserLicenses>(); foreach (var item in hidLicenseNumberList.Value.Split(',')) { if (string.IsNullOrEmpty(item)) { continue; } Model.UserLicenses model = new Model.UserLicenses(); model.LicenseNumber = item; model.UserId = CurrUser.iUserID; ulList.Add(model); } BLL.UserLicenses ulBll = new BLL.UserLicenses(); ulBll.UpdatebatchByUserID(ulList); BindLicensesList(); } catch (Exception ex) { LPLog.LogMessage(ex.Message); PageCommon.AlertMsg(this, "Failed to Save User Licenses:" + ex.Message); return; } } #endregion if (!string.IsNullOrEmpty(this.tbPWD.Text)) { try { ServiceManager sm = new ServiceManager(); using (LP2ServiceClient service = sm.StartServiceClient()) { ReqHdr hdr; UpdateADUserRequest uReq = new UpdateADUserRequest(); hdr = new ReqHdr(); hdr.UserId = CurrUser.iUserID; uReq.hdr = hdr; uReq.Command = UserMgrCommandType.ChangePassword; uReq.AD_OU_Filter = this.hiPrefix.Value; uReq.AD_User = new LP_Service.User(); uReq.AD_User.Password = this.tbPWD.Text; uReq.AD_User.Username = this.hiUsername.Value; uReq.AD_User.Firstname = this.hiFirstName.Value; uReq.AD_User.Lastname = this.hiLastName.Value; uReq.AD_User.Email = this.lbEmail.Text; UpdateADUserResponse uResponse; uResponse = service.UpdateADUser(uReq); if (!uResponse.hdr.Successful) { PageCommon.AlertMsg(this, "Failed to update your password. Please make sure your new password meets the password policy requirements."); LPLog.LogMessage(LogType.Logerror, "Failed to change password in AD, username="******"Failed to change password in AD, reason: User Manager is not running."); return; } catch (Exception ex) { PageCommon.AlertMsg(this, "Failed to change password in AD, exception info: " + ex.Message); LPLog.LogMessage(LogType.Logerror, "Failed to change password in AD, username="******", Exception:" + ex.Message); return; } } ClientFun("sucsmsg", "alert('Saved!');"); } catch (Exception ex) { PageCommon.AlertMsg(this, "Failed to save user Personalization - Settings info, reason:" + ex.Message); LPLog.LogMessage(LogType.Logerror, "Failed to save user Personalization - Settings info: " + ex.Message); return; } }
/// <summary> /// update AD /// </summary> /// <param name="dicIDs"></param> private void UpdateAD(Dictionary <int, int> dicIDs, UserMgrCommandType uType) { ServiceManager sm = new ServiceManager(); using (LP2ServiceClient service = sm.StartServiceClient()) { UpdateADUserRequest uReq; UpdateADUserResponse uResponse; ReqHdr hdr; Dictionary <string, string> dicFailed = new Dictionary <string, string>(); foreach (KeyValuePair <int, int> kvp in dicIDs) { hdr = new ReqHdr(); hdr.UserId = kvp.Value; uReq = new UpdateADUserRequest(); uReq.hdr = hdr; uReq.Command = uType; uReq.AD_OU_Filter = this.hiPrefix.Value; uReq.AD_User = new LP_Service.User(); uReq.AD_User.Username = gridUserList.DataKeys[kvp.Key]["Username"].ToString(); uReq.AD_User.Firstname = gridUserList.DataKeys[kvp.Key]["FirstName"].ToString(); uReq.AD_User.Lastname = gridUserList.DataKeys[kvp.Key]["LastName"].ToString(); uReq.AD_User.Email = gridUserList.DataKeys[kvp.Key]["EmailAddress"].ToString(); try { uResponse = service.UpdateADUser(uReq); if (!uResponse.hdr.Successful) { dicFailed.Add(gridUserList.DataKeys[kvp.Key]["Username"].ToString(), uResponse.hdr.StatusInfo); } } catch (System.ServiceModel.EndpointNotFoundException ee) { dicFailed.Add(gridUserList.DataKeys[kvp.Key]["Username"].ToString(), ee.Message); } catch (Exception ex) { dicFailed.Add(gridUserList.DataKeys[kvp.Key]["Username"].ToString(), ex.Message); } } if (dicFailed.Count > 0) { StringBuilder sbErrorMsg = new StringBuilder(); StringBuilder sbErrorLog = new StringBuilder(); foreach (KeyValuePair <string, string> kvp in dicFailed) { if (sbErrorMsg.Length > 0) { sbErrorMsg.Append(","); } sbErrorMsg.Append(kvp.Key); if (sbErrorLog.Length > 0) { sbErrorLog.Append(","); } sbErrorLog.Append(string.Format("{0}:{1}", kvp.Key, kvp.Value)); } // get UserMgrCommandType string string strType = ""; switch (uType) { case UserMgrCommandType.DisableUser: strType = "disable"; break; case UserMgrCommandType.DeleteUser: strType = "delete"; break; default: strType = ""; break; } ClientFun(this.updatePanel, "failedtodeleteuserinad", string.Format("alert('Failed to {0} the selected user account(s), username = {1}, please try it again.');", strType, sbErrorMsg.ToString())); //PageCommon.AlertMsg(this, string.Format("Failed to {0} the selected user account(s), username = {1}", strType, sbErrorMsg.ToString())); LPLog.LogMessage(LogType.Logerror, string.Format("Failed to {0} the selected user account(s): {1}", strType, sbErrorLog.ToString())); } } }