예제 #1
0
        public static List<RoleInfo> GetPortalRoles(int PortalID, int IsAll, string UserName)
        {
            string sp = "[dbo].[sp_PortalRoleList]";
            SQLHandler sagesql = new SQLHandler();

            List<KeyValuePair<string, object>> ParamCollInput = new List<KeyValuePair<string, object>>();
            ParamCollInput.Add(new KeyValuePair<string, object>("@PortalID", PortalID));
            ParamCollInput.Add(new KeyValuePair<string, object>("@IsAll", IsAll));
            ParamCollInput.Add(new KeyValuePair<string, object>("@Username", UserName));

            List<RoleInfo> lstPortalRoles = new List<RoleInfo>();
            try
            {
                SqlDataReader reader;
                reader = sagesql.ExecuteAsDataReader(sp, ParamCollInput);
                while (reader.Read())
                {
                    RoleInfo obj = new RoleInfo();
                    obj.RoleName = reader["RoleName"].ToString();
                    obj.RoleID = new Guid(reader["RoleID"].ToString());
                    lstPortalRoles.Add(obj);
                }
                reader.Close();
                return lstPortalRoles;

            }
            catch (Exception ex)
            {

                throw (ex);
            }

        }
 /// <summary>
 /// Update role.
 /// </summary>
 /// <param name="role">Object of RoleInfo class.</param>
 public override void UpdateRole(RoleInfo role)
 {
     throw new NotImplementedException();
 }
예제 #3
0
        public static void CreateRole(RoleInfo obj, out RoleCreationStatus status)
        {
            List<KeyValuePair<string, object>> ParamCollInput = new List<KeyValuePair<string, object>>();
            ParamCollInput.Add(new KeyValuePair<string, object>("@ApplicationName", obj.ApplicationName));
            ParamCollInput.Add(new KeyValuePair<string, object>("@RoleName", obj.RoleName));
            ParamCollInput.Add(new KeyValuePair<string, object>("@PortalID", obj.PortalID));
            ParamCollInput.Add(new KeyValuePair<string, object>("@IsActive", obj.IsActive));
            ParamCollInput.Add(new KeyValuePair<string, object>("@AddedOn", obj.AddedOn));
            ParamCollInput.Add(new KeyValuePair<string, object>("@AddedBy", obj.AddedBy));

            List<KeyValuePair<string, object>> ParamCollOutput = new List<KeyValuePair<string, object>>();
            ParamCollOutput.Add(new KeyValuePair<string, object>("@ErrorCode", 0));

            try
            {
                SageFrameSQLHelper sagesql = new SageFrameSQLHelper();
                List<KeyValuePair<int, string>> OutputValColl = new List<KeyValuePair<int, string>>();
                OutputValColl = sagesql.ExecuteNonQueryWithMultipleOutput("[dbo].[usp_sf_CreateRole]", ParamCollInput, ParamCollOutput);
                int ErrorCode = int.Parse(OutputValColl[0].Value);

                switch (ErrorCode)
                {
                    case 1:
                        status = RoleCreationStatus.DUPLICATE_ROLE;
                        break;
                    default:
                        status = RoleCreationStatus.SUCCESS;
                        break;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }


        }
 /// <summary>
 /// Create role.
 /// </summary>
 /// <param name="role">Object of RoleInfo class.</param>
 /// <param name="status">Role creation status.<see cref="T: SageFrame.Security.Helpers.RoleCreationStatus"/></param>
 public override void CreateRole(RoleInfo role, out RoleCreationStatus status)
 {
     MembershipDataProvider.CreateRole(role, out status);
 }
		public abstract void UpdateRole(RoleInfo role);		
 public abstract void CreateRole(RoleInfo role, out RoleCreationStatus status);
예제 #7
0
        protected void imgAdd_Click(object sender, EventArgs e)
        {
            try
            {
                    string rolePrefix = GetPortalSEOName + "_";   
                    RoleInfo objRole = new RoleInfo();
                    objRole.ApplicationName =Membership.ApplicationName;
                    objRole.RoleName = txtRole.Text;
                    objRole.PortalID = GetPortalID;
                    objRole.IsActive = 1;
                    objRole.AddedOn = DateTime.Now;
                    objRole.AddedBy = GetUsername;

                    RoleController r = new RoleController();
                    RoleCreationStatus status = new RoleCreationStatus();
                    r.CreateRole(objRole, out status);                   
                    if (status == RoleCreationStatus.DUPLICATE_ROLE)
                    {
                        ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("UserManagement", "ThisRoleAlreadyExists"), "", SageMessageType.Error);
                        
                    }
                    else if (status == RoleCreationStatus.SUCCESS)
                    {
                        BindRoles();
                        pnlRole.Visible = false;
                        pnlRoles.Visible = true;                       
                        ShowMessage(SageMessageTitle.Information.ToString(), GetSageMessage("UserManagement", "RoleSavedSuccessfully"), "", SageMessageType.Success);
                    }
                   
               
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
        }
        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;
            }

        }