protected void lbtnDelete_Click(object sender, EventArgs e) { Dictionary <int, int> dicIDs = new Dictionary <int, int>(); // Get userid of current selected row foreach (GridViewRow row in gridUserList.Rows) { if (DataControlRowType.DataRow == row.RowType) { CheckBox ckbChecked = row.FindControl("ckbSelected") as CheckBox; if (null != ckbChecked && ckbChecked.Checked) { dicIDs.Add(row.RowIndex, (int)gridUserList.DataKeys[row.RowIndex].Value); originalUserId = (int)gridUserList.DataKeys[row.RowIndex].Value; } } } if (dicIDs.Count > 0) { ReassignProspect(originalUserId); try { // get all loans assigned to this user, dicIDs must have only one item in this case DataSet dsUserLoan = LoanTeamManager.GetUserLoan(dicIDs.FirstOrDefault().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) { 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; List <ReassignUserInfo> uList = new List <ReassignUserInfo>(); Model.Users userToDelete = UsersManager.GetModel(dicIDs.FirstOrDefault().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, originalUserId, roleId, requester); } UsersManager.DeleteUsers(dicIDs.Select(i => i.Value).ToList(), CurrUser.iUserID, nReassignUserId); } else { // PageCommon.WriteJsEnd(this, string.Format("Failed to reassign loan, reason:{0}.", respone.hdr.StatusInfo), PageCommon.Js_RefreshSelf); // return; } } catch (System.ServiceModel.EndpointNotFoundException ex) { LPLog.LogMessage(ex.Message); // PageCommon.WriteJsEnd(this, "Failed to reassign loan, reason: Point Manager is not running.", PageCommon.Js_RefreshSelf); } catch (Exception exception) { LPLog.LogMessage(exception.Message); // PageCommon.WriteJsEnd(this, string.Format("Failed to reassign loan, reason:{0}.", exception.Message), PageCommon.Js_RefreshSelf); } } } else { UsersManager.DeleteUsers(dicIDs.Select(i => i.Value).ToList(), CurrUser.iUserID, nReassignUserId); } BindGrid(); } catch (Exception ex) { ClientFun(this.updatePanel, "failedtodeleteuserinad", "alert('Failed to delete the selected user account(s), please try it again.');"); //PageCommon.AlertMsg(this, "Failed to delete the selected users, please try it again."); LPLog.LogMessage(LogType.Logerror, "Failed to delete the selected user account(s): " + ex.Message); return; } try { UpdateAD(dicIDs, UserMgrCommandType.DeleteUser); } catch (Exception ex) { ClientFun(this.updatePanel, "failed to delete user in ad", string.Format("alert('Failed to delete the selected user account(s) in AD, Exception: {0}');", ex.Message.Replace("'", "\""))); //PageCommon.AlertMsg(this, "Failed to delete the selected user account in AD."); LPLog.LogMessage(LogType.Logerror, "Failed to delete the selected user account(s), exception: " + ex.Message); return; } } }