protected void btnUserImport_Click(object sender, EventArgs e)
        {
            try
            {
                bool Flag = false;
                DataSet userImportDataSet = ImportUserFile();
                List<string> lstColumnHeader = new List<string>();
                List<string> ObjMappingList = MappingList();

                if (userImportDataSet.Tables.Count > 0)
                {
                    int columnLength = userImportDataSet.Tables[0].Columns.Count;
                    for (int i = 0; i < columnLength; i++)
                    {
                        lstColumnHeader.Add(userImportDataSet.Tables[0].Columns[i].ColumnName);
                    }

                    Flag = !ObjMappingList.Except(lstColumnHeader).Any();
                    if (Flag)
                    {
                        for (int i = 0; i < columnLength; i++)
                        {
                            if (txtImportUserName.Text == userImportDataSet.Tables[0].Columns[i].ColumnName)
                            {
                                userImportDataSet.Tables[0].Columns[i].ColumnName = "UserName";
                            }
                            if (txtImportFirstName.Text == userImportDataSet.Tables[0].Columns[i].ColumnName)
                            {
                                userImportDataSet.Tables[0].Columns[i].ColumnName = "FirstName";
                            }
                            if (txtImportLastName.Text == userImportDataSet.Tables[0].Columns[i].ColumnName)
                            {
                                userImportDataSet.Tables[0].Columns[i].ColumnName = "LastName";
                            }
                            if (txtImportEmail.Text == userImportDataSet.Tables[0].Columns[i].ColumnName)
                            {
                                userImportDataSet.Tables[0].Columns[i].ColumnName = "Email";
                            }
                            if (txtImportPassword.Text == userImportDataSet.Tables[0].Columns[i].ColumnName)
                            {
                                userImportDataSet.Tables[0].Columns[i].ColumnName = "Password";
                            }
                            if (txtImportPasswordSalt.Text == userImportDataSet.Tables[0].Columns[i].ColumnName)
                            {
                                userImportDataSet.Tables[0].Columns[i].ColumnName = "PasswordSalt";
                            }
                            if (txtImportPasswordFormat.Text == userImportDataSet.Tables[0].Columns[i].ColumnName)
                            {
                                userImportDataSet.Tables[0].Columns[i].ColumnName = "PasswordFormat";
                            }
                            if (txtImportRoleName.Text == userImportDataSet.Tables[0].Columns[i].ColumnName)
                            {
                                userImportDataSet.Tables[0].Columns[i].ColumnName = "RoleName";
                            }
                            if (txtImportPortalID.Text == userImportDataSet.Tables[0].Columns[i].ColumnName)
                            {
                                userImportDataSet.Tables[0].Columns[i].ColumnName = "PortalID";
                            }
                            if (txtImportIsApproved.Text == userImportDataSet.Tables[0].Columns[i].ColumnName)
                            {
                                userImportDataSet.Tables[0].Columns[i].ColumnName = "IsActive";
                            }
                        }
                    }
                    else
                    {
                        ShowMessage("", GetSageMessage("UserManagement", "ColumnMappingError"), "", SageMessageType.Alert);
                        clearField();
                        return;
                    }

                    //Listing Excel Users
                    foreach (DataRow dr in userImportDataSet.Tables[0].Rows)
                    {
                        ExportUserInfo userImportInfo = new ExportUserInfo();
                        userImportInfo.UserName = dr["UserName"].ToString();
                        userImportInfo.FirstName = dr["FirstName"].ToString();
                        userImportInfo.LastName = dr["LastName"].ToString();
                        userImportInfo.Email = dr["Email"].ToString();
                        userImportInfo.Password = dr["Password"].ToString();
                        userImportInfo.PasswordSalt = dr["PasswordSalt"].ToString();
                        userImportInfo.PasswordFormat = dr["PasswordFormat"].ToString();
                        userImportInfo.RoleName = dr["RoleName"].ToString();
                        userImportInfo.PortalID = Convert.ToInt32(dr["PortalID"]);
                        userImportInfo.IsApproved = Convert.ToBoolean(dr["IsActive"]);
                        lstUserImportUsers.Add(userImportInfo);
                    }

                    //Extracting Excel Roles

                    List<RoleInfo> lstExcelRolesSplit = new List<RoleInfo>();
                    foreach (ExportUserInfo objExport in lstUserImportUsers)
                    {
                        string[] excelRolesArr = objExport.RoleName.Split(',');
                        foreach (string role in excelRolesArr)
                        {
                            RoleInfo objRoles = new RoleInfo();
                            objRoles.PortalID = objExport.PortalID;
                            objRoles.RoleName = role.Trim();
                            lstExcelRolesSplit.Add(objRoles);
                        }
                    }

                    List<RoleInfo> lstExcelRolesIdentical = new List<RoleInfo>();
                    var ExcelRolesIdentical = lstExcelRolesSplit.Select(i => new { i.RoleName, i.PortalID }).Distinct();
                    foreach (var objRole in ExcelRolesIdentical)
                    {
                        RoleInfo objRoleInfo = new RoleInfo();
                        objRoleInfo.RoleName = objRole.RoleName;
                        objRoleInfo.PortalID = objRole.PortalID;
                        lstExcelRolesIdentical.Add(objRoleInfo);
                    }

                    //Extracting Sage Roles
                    List<RolesManagementInfo> lstSageRoles = new List<RolesManagementInfo>();
                    RolesManagementController objController = new RolesManagementController();
                    lstSageRoles = objController.GetSageFramePortalList();
                    List<RoleInfo> lstSageRolesSplit = new List<RoleInfo>();
                    foreach (RolesManagementInfo objRoleMgntInfo in lstSageRoles)
                    {
                        RoleInfo objSageRoles = new RoleInfo();
                        objSageRoles.RoleName = objRoleMgntInfo.RoleName;
                        objSageRoles.PortalID = objRoleMgntInfo.PortalID;
                        lstSageRolesSplit.Add(objSageRoles);
                    }

                    //Retrieve Identical Roles in Sage Roles and Excel Roles
                    List<RoleInfo> lstIdenticalRoles = lstExcelRolesIdentical.Except(lstSageRolesSplit).ToList();

                    //Adding Identical Roles in SageRoles
                    for (int i = 0; i < lstIdenticalRoles.Count; i++)
                    {
                        RoleInfo objRole = new RoleInfo();
                        string rolePrefix = GetPortalSEOName + "_";
                        objRole.ApplicationName = Membership.ApplicationName;
                        objRole.RoleName = lstIdenticalRoles[i].RoleName;
                        objRole.PortalID = lstIdenticalRoles[i].PortalID;
                        objRole.IsActive = 1;
                        objRole.AddedOn = DateTime.Now;
                        objRole.AddedBy = GetUsername;
                        RoleController objRoleCon = new RoleController();
                        RoleCreationStatus status = new RoleCreationStatus();
                        objRoleCon.CreateRole(objRole, out status);
                    }

                    //Listing SageFrame Users
                    UserProfileController objUserProfile = new UserProfileController();
                    List<ExportUserInfo> lstSageUsers = objUserProfile.GetSageFrameUserList();

                    //Extracting Excel Username
                    List<string> lstExcelUserName = new List<string>();
                    lstExcelUserName = lstUserImportUsers.Select(x => x.UserName).ToList();

                    //Extracting Excel Email
                    List<string> lstExcelEmail = new List<string>();
                    lstExcelEmail = lstUserImportUsers.Select(x => x.Email).ToList();

                    //Extracting SageFrame Username
                    List<string> lstSageUserName = new List<string>();
                    lstSageUserName = lstSageUsers.Select(x => x.UserName).ToList();

                    //Extracting SageFrame Email
                    List<string> lstSageEmail = new List<string>();
                    lstSageEmail = lstSageUsers.Select(x => x.Email).ToList();

                    //Check duplicacy of Self Excel Users and Email
                    List<string> lstUserNameDuplicacyinExcel = new List<string>();
                    lstUserNameDuplicacyinExcel = lstExcelUserName.GroupBy(x => x).Where(g => g.Count() > 1).Select(y => y.Key).ToList();

                    List<string> lstEmailDuplicacyinExcel = new List<string>();
                    lstEmailDuplicacyinExcel = lstExcelEmail.GroupBy(x => x).Where(g => g.Count() > 1).Select(y => y.Key).ToList();

                    if (lstUserNameDuplicacyinExcel.Count > 0 || lstEmailDuplicacyinExcel.Count > 0)
                    {
                        ShowMessage("", GetSageMessage("UserManagement", "DuplicateUsers"), "", SageMessageType.Alert);
                        clearField();
                        DeleteTempFolder();
                        return;
                    }

                    //check UserName duplicacy SageUsers And Excel Users               
                    List<string> lstUserNameDuplicacy = new List<string>();
                    lstUserNameDuplicacy = lstExcelUserName.Intersect(lstSageUserName).ToList();

                    //Removing duplicate List by UserName
                    ExportUserInfo dupUserListByUName = null;
                    List<ExportUserInfo> lstdubUserListByName = new List<ExportUserInfo>();
                    foreach (string DupUserName in lstUserNameDuplicacy)
                    {
                        List<ExportUserInfo> obj = lstUserImportUsers;
                        dupUserListByUName = lstUserImportUsers.Single(x => x.UserName == DupUserName);
                        lstUserImportUsers.Remove(dupUserListByUName);
                        //list users in excel
                        lstdubUserListByName.Add(dupUserListByUName);
                    }

                    //Extracting Email duplicacy in SageEmail and listUserImportUsers
                    List<string> lstExcelEmailInImportUsers = new List<string>();
                    lstExcelEmailInImportUsers = lstUserImportUsers.Select(x => x.Email).ToList();

                    //check Email duplicacy SageEmail And Excel Email 
                    List<string> lstEmailDuplicacy = new List<string>();
                    if (!m.RequireUniqueEmail)
                    {
                        lstEmailDuplicacy = lstExcelEmailInImportUsers.Intersect(lstSageEmail).ToList();
                    }
                    //Removing duplicate List by Email
                    ExportUserInfo dupUserListByEmail = null;
                    List<ExportUserInfo> lstdubUserListByEmail = new List<ExportUserInfo>();
                    if (lstUserImportUsers.Count != 0)
                    {
                        foreach (string DupEmail in lstEmailDuplicacy)
                        {
                            List<ExportUserInfo> obj = lstUserImportUsers;
                            dupUserListByEmail = lstUserImportUsers.Single(x => x.Email == DupEmail);
                            lstUserImportUsers.Remove(dupUserListByEmail);
                            //list users in excel
                            lstdubUserListByEmail.Add(dupUserListByEmail);
                        }
                    }

                    //Retrieve Duplicate UserList in SageUsers and Excel Users
                    lstDuplicateUserList = lstdubUserListByName.Concat(lstdubUserListByEmail).ToList();

                    //Retrieve Identical UserList in SageUsers and Excel Users
                    List<ExportUserInfo> lstIdenticalUserList = lstUserImportUsers;

                    //Adding Identical User List in SageUserList
                    if (lstIdenticalUserList.Count > 0)
                    {
                        for (int i = 0; i < lstIdenticalUserList.Count; i++)
                        {
                            UserInfo objUser = new UserInfo();
                            objUser.ApplicationName = Membership.ApplicationName;
                            objUser.FirstName = lstIdenticalUserList[i].FirstName;
                            objUser.UserName = lstIdenticalUserList[i].UserName;
                            objUser.LastName = lstIdenticalUserList[i].LastName;
                            objUser.Password = lstIdenticalUserList[i].Password;
                            objUser.PasswordSalt = lstIdenticalUserList[i].PasswordSalt;
                            objUser.Email = lstIdenticalUserList[i].Email;
                            objUser.SecurityQuestion = "";
                            objUser.SecurityAnswer = "";
                            objUser.IsApproved = lstIdenticalUserList[i].IsApproved;
                            objUser.CurrentTimeUtc = DateTime.Now;
                            objUser.CreatedDate = DateTime.Now;
                            objUser.UniqueEmail = 0;
                            objUser.PasswordFormat = Int32.Parse(lstIdenticalUserList[i].PasswordFormat);
                            objUser.PortalID = lstIdenticalUserList[i].PortalID;
                            objUser.AddedOn = DateTime.Now;
                            objUser.AddedBy = GetUsername;
                            objUser.UserID = Guid.NewGuid();
                            objUser.RoleNames = lstIdenticalUserList[i].RoleName;
                            objUser.StoreID = GetStoreID;
                            objUser.CustomerID = GetCustomerID;
                            UserCreationStatus status = new UserCreationStatus();
                            MembershipDataProvider.CreatePortalUser(objUser, out status, UserCreationMode.CREATE);
                        }
                    }
                    else
                    {
                        lblDuplicateUser.Visible = true;
                        ShowMessage("", GetSageMessage("UserManagement", "UsersNotAdded"), "", SageMessageType.Error);
                        ExportDuplicateUserList();
                    }
                    if (lstDuplicateUserList.Count > 0 && lstIdenticalUserList.Count > 0)
                    {
                        lblDuplicateUser.Visible = true;
                        ShowMessage("", GetSageMessage("UserManagement", "UsersAddedSuccessfullyWithDuplicateUserReport"), "", SageMessageType.Success);
                        ExportDuplicateUserList();
                    }
                    if (lstDuplicateUserList.Count == 0 && lstIdenticalUserList.Count > 0)
                    {
                        ShowMessage("", GetSageMessage("UserManagement", "UsersAddedSuccessfully"), "", SageMessageType.Success);
                    }
                    clearField();
                    DeleteTempFolder();

                }
            }
            catch (Exception ex)
            {

                throw ex;
            }

        }
        private void UserExportToExcel()
        {
            string csv = string.Empty;
            try
            {
                List<ExportUserInfo> lstInfo = new List<ExportUserInfo>();
                UserProfileController objCon = new UserProfileController();
                lstInfo = objCon.GetUserExportList();
                if (lstInfo.Count > 0)
                {
                    csv += "UserName ,";
                    csv += "FirstName ,";
                    csv += "LastName,";
                    csv += "Email,";
                    csv += "Password,";
                    csv += "PasswordSalt,";
                    csv += "PasswordFormat,";
                    csv += "RoleName,";
                    csv += "PortalID,";
                    csv += "IsActive,";
                    csv += "\r\n";

                    foreach (ExportUserInfo objInfo in lstInfo)
                    {
                        csv += objInfo.UserName + ",";
                        csv += objInfo.FirstName + ",";
                        csv += objInfo.LastName + ",";
                        csv += "\"" + objInfo.Email + "\"" + ",";
                        csv += objInfo.Password + ",";
                        csv += objInfo.PasswordSalt + ",";
                        csv += objInfo.PasswordFormat + ",";
                        csv += "\"" + objInfo.RoleName + "\"" + ",";
                        csv += objInfo.PortalID + ",";
                        csv += objInfo.IsApproved + ",";
                        csv += "\r\n";
                    }

                    ExportToExcel(ref csv, "User-Report");
                }
                else
                {
                    ShowMessage(SageMessageTitle.Exception.ToString(), "No any data to export", "", SageMessageType.Alert);
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }