예제 #1
0
        /// <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);
                    }
                }
            }
        }