private void LoadRoleList2DDL(string selected_value)
 {
     ddlRoleList.Items.Clear();
     string ApplicationId = ddlApplicationList.SelectedValue;
     RoleController app_obj = new RoleController();
     DataTable dt_app = app_obj.GetRoleListByApplicationId(ApplicationId);            
     ddlRoleList.DataSource = dt_app;
     ddlRoleList.DataTextField = "RoleName";
     ddlRoleList.DataValueField = "RoleId";
     ddlRoleList.DataBind();            
     ddlRoleList.SelectedValue = selected_value;
     ddlRoleList.Enabled = false;
 }
 private void LoadRoleList2DDL()
 {
     ddlRoleList.Items.Clear();
     string ApplicationId = ddlApplicationList.SelectedValue;
     RoleController app_obj = new RoleController();
     DataTable dt_app = app_obj.GetRoleListByApplicationId(ApplicationId);
     ddlRoleList.AutoPostBack = true;
     ddlRoleList.DataSource = dt_app;
     ddlRoleList.DataTextField = "RoleName";
     ddlRoleList.DataValueField = "RoleId";
     ddlRoleList.DataBind();
     //ddlRoleList.Items.Insert(0, new ListItem("- Chọn -", ""));
     ddlRoleList.SelectedIndex = 0;
 }
 public static bool DeleteUserRole(int roleId, UserInfo objUser, PortalSettings PortalSettings, bool notifyUser)
 {
     RoleController objRoleController = new RoleController();
     RoleInfo objRole = objRoleController.GetRole(roleId, PortalSettings.PortalId);
     return DeleteUserRole(objUser, objRole, PortalSettings, notifyUser);
 }
 public static void AddUserRole(UserInfo objUser, RoleInfo objRole, PortalSettings PortalSettings, System.DateTime effDate, System.DateTime expDate, int userId, bool notifyUser)
 {
     RoleController objRoleController = new RoleController();
     UserRoleInfo objUserRole = objRoleController.GetUserRole(PortalSettings.PortalId, objUser.UserID, objRole.RoleID);
     Services.Log.EventLog.EventLogController objEventLog = new Services.Log.EventLog.EventLogController();
     objRoleController.AddUserRole(PortalSettings.PortalId, objUser.UserID, objRole.RoleID, effDate, expDate);
     objUser.RefreshRoles = true;
     UserController.UpdateUser(PortalSettings.PortalId, objUser);
     if (objUserRole == null)
     {
         objEventLog.AddLog("Role", objRole.RoleName, PortalSettings, userId, Services.Log.EventLog.EventLogController.EventLogType.USER_ROLE_CREATED);
         if (notifyUser)
         {
             SendNotification(objUser, objRole, PortalSettings, UserRoleActions.@add);
         }
     }
     else
     {
         objEventLog.AddLog("Role", objRole.RoleName, PortalSettings, userId, Services.Log.EventLog.EventLogController.EventLogType.USER_ROLE_UPDATED);
         if (notifyUser)
         {
             objUserRole = objRoleController.GetUserRole(PortalSettings.PortalId, objUser.UserID, objRole.RoleID);
             SendNotification(objUser, objRole, PortalSettings, UserRoleActions.update);
         }
     }
 }
        private static void SendNotification(UserInfo objUser, RoleInfo objRole, PortalSettings PortalSettings, UserRoleActions Action)
        {
            RoleController objRoles = new RoleController();
            ArrayList Custom = new ArrayList();
            Custom.Add(objRole.RoleName);
            Custom.Add(objRole.Description);
            switch (Action)
            {
                case UserRoleActions.add:
                case UserRoleActions.update:
                    string preferredLocale = objUser.Profile.PreferredLocale;
                    if (string.IsNullOrEmpty(preferredLocale))
                    {
                        preferredLocale = PortalSettings.DefaultLanguage;
                    }
                    CultureInfo ci = new CultureInfo(preferredLocale);
                    UserRoleInfo objUserRole = objRoles.GetUserRole(PortalSettings.PortalId, objUser.UserID, objRole.RoleID);
                    if (Null.IsNull(objUserRole.EffectiveDate))
                    {
                        Custom.Add(DateTime.Today.ToString("g", ci));
                    }
                    else
                    {
                        Custom.Add(objUserRole.EffectiveDate.ToString("g", ci));
                    }
                    if (Null.IsNull(objUserRole.ExpiryDate))
                    {
                        Custom.Add("-");
                    }
                    else
                    {
                        Custom.Add(objUserRole.ExpiryDate.ToString("g", ci));
                    }
                    break;
                case UserRoleActions.delete:
                    Custom.Add("");
                    break;
            }
            Message _message = new Message();
            _message.FromUserID = PortalSettings.AdministratorId;
            _message.ToUserID = objUser.UserID;
            _message.Subject = Services.Localization.Localization.GetSystemMessage(objUser.Profile.PreferredLocale, PortalSettings, "EMAIL_ROLE_" + RoleController.UserRoleActionsCaption[(int)Action] + "_SUBJECT", objUser);
            _message.Body = Localization.GetSystemMessage(objUser.Profile.PreferredLocale, PortalSettings, "EMAIL_ROLE_" + RoleController.UserRoleActionsCaption[(int)Action] + "_BODY", objUser, Services.Localization.Localization.GlobalResourceFile, Custom);
            _message.Status = MessageStatusType.Unread;

            //_messagingController.SaveMessage(_message);
            //Services.Mail.Mail.SendEmail(PortalSettings.Email, objUser.Email, _message.Subject, _message.Body);
        }
 private static void DeserializeModulePermissions(XmlNodeList nodeModulePermissions, int PortalId, int TabId, ModuleInfo objModule)
 {
     RoleController objRoleController = new RoleController();
     PermissionController objPermissionController = new PermissionController();
     PermissionInfo objPermission;
     int PermissionID;
     ArrayList arrPermissions;
     int i;
     foreach (XmlNode node in nodeModulePermissions)
     {
         string PermissionKey = XmlUtils.GetNodeValue(node.CreateNavigator(), "permissionkey");
         string PermissionCode = XmlUtils.GetNodeValue(node.CreateNavigator(), "permissioncode");
         string RoleName = XmlUtils.GetNodeValue(node.CreateNavigator(), "rolename");
         bool AllowAccess = XmlUtils.GetNodeValueBoolean(node, "allowaccess");
         int RoleID = int.MinValue;
         switch (RoleName)
         {
             case Globals.glbRoleAllUsersName:
                 RoleID = Convert.ToInt32(Globals.glbRoleAllUsers);
                 break;
             case Common.Globals.glbRoleUnauthUserName:
                 RoleID = Convert.ToInt32(Globals.glbRoleUnauthUser);
                 break;
             default:
                 RoleInfo objRole = objRoleController.GetRoleByName(PortalId, RoleName);
                 if (objRole != null)
                 {
                     RoleID = objRole.RoleID;
                 }
                 break;
         }
         if (RoleID != int.MinValue)
         {
             PermissionID = -1;
             arrPermissions = objPermissionController.GetPermissionByCodeAndKey(PermissionCode, PermissionKey);
             for (i = 0; i <= arrPermissions.Count - 1; i++)
             {
                 objPermission = (PermissionInfo)arrPermissions[i];
                 PermissionID = objPermission.PermissionID;
             }
             if (PermissionID != -1)
             {
                 ModulePermissionInfo objModulePermission = new ModulePermissionInfo();
                 objModulePermission.ModuleID = objModule.ModuleID;
                 objModulePermission.PermissionID = PermissionID;
                 objModulePermission.RoleID = RoleID;
                 objModulePermission.AllowAccess = Convert.ToBoolean(XmlUtils.GetNodeValue(node.CreateNavigator(), "allowaccess"));
                 objModule.ModulePermissions.Add(objModulePermission);
             }
         }
     }
 }
 private int CreateRole(RoleInfo role)
 {
     RoleInfo objRoleInfo;
     RoleController objRoleController = new RoleController();
     int roleId = Null.NullInteger;
     objRoleInfo = objRoleController.GetRoleByName(role.PortalID, role.RoleName);
     if (objRoleInfo == null)
     {
         roleId = objRoleController.AddRole(role);
     }
     else
     {
         roleId = objRoleInfo.RoleID;
     }
     return roleId;
 }
 private void LoadRoleList2DDL(string selected_value)
 {
     ddlRoleList.Items.Clear(); //DROPDOWNLIST        
     RoleController role_obj = new RoleController();
     string ApplicationId = ddlApplicationList.SelectedValue;
     DataTable dt = role_obj.GetRoleListByApplicationId(ApplicationId);           
     
     ddlRoleList.DataSource = dt;
     ddlRoleList.DataTextField = "RoleName";
     ddlRoleList.DataValueField = "RoleId";            
     ddlRoleList.Items.Insert(0, new ListItem("- Chọn -", ""));
     ddlRoleList.SelectedValue = selected_value;
     ddlRoleList.DataBind();   
 }
 private static void DeserializeTabPermissions(XmlNodeList nodeTabPermissions, TabInfo objTab, bool IsAdminTemplate)
 {
     Security.Permissions.PermissionController objPermissionController = new Security.Permissions.PermissionController();
     Security.Permissions.PermissionInfo objPermission;
     Security.Permissions.TabPermissionInfo objTabPermission;
     RoleController objRoleController = new RoleController();
     RoleInfo objRole;
     int RoleID;
     int PermissionID = 0;
     string PermissionKey;
     string PermissionCode;
     string RoleName;
     bool AllowAccess;
     ArrayList arrPermissions;
     int i;
     foreach (XmlNode xmlTabPermission in nodeTabPermissions)
     {
         PermissionKey = XmlUtils.GetNodeValue(xmlTabPermission.CreateNavigator(), "permissionkey");
         PermissionCode = XmlUtils.GetNodeValue(xmlTabPermission.CreateNavigator(), "permissioncode");
         RoleName = XmlUtils.GetNodeValue(xmlTabPermission.CreateNavigator(), "rolename");
         AllowAccess = XmlUtils.GetNodeValueBoolean(xmlTabPermission, "allowaccess");
         arrPermissions = objPermissionController.GetPermissionByCodeAndKey(PermissionCode, PermissionKey);
         for (i = 0; i <= arrPermissions.Count - 1; i++)
         {
             objPermission = (Security.Permissions.PermissionInfo)arrPermissions[i];
             PermissionID = objPermission.PermissionID;
         }
         RoleID = int.MinValue;
         switch (RoleName)
         {
             case Globals.glbRoleAllUsersName:
                 RoleID = Convert.ToInt32(Globals.glbRoleAllUsers);
                 break;
             case Common.Globals.glbRoleUnauthUserName:
                 RoleID = Convert.ToInt32(Globals.glbRoleUnauthUser);
                 break;
             default:
                 PortalController objPortals = new PortalController();
                 PortalInfo objPortal = objPortals.GetPortal(objTab.PortalID);
                 objRole = objRoleController.GetRoleByName(objPortal.PortalID, RoleName);
                 if (objRole != null)
                 {
                     RoleID = objRole.RoleID;
                 }
                 else
                 {
                     if (IsAdminTemplate && RoleName.ToLower() == "administrators")
                     {
                         RoleID = objPortal.AdministratorRoleId;
                     }
                 }
                 break;
         }
         if (RoleID != int.MinValue)
         {
             objTabPermission = new Security.Permissions.TabPermissionInfo();
             objTabPermission.TabID = objTab.TabID;
             objTabPermission.PermissionID = PermissionID;
             objTabPermission.RoleID = RoleID;
             objTabPermission.AllowAccess = AllowAccess;
             objTab.TabPermissions.Add(objTabPermission);
         }
     }
 }
 public static string GetRoleName(int RoleID)
 {
     if (Convert.ToString(RoleID) == glbRoleAllUsers)
     {
         return "All Users";
     }
     else if (Convert.ToString(RoleID) == glbRoleUnauthUser)
     {
         return "Unauthenticated Users";
     }
     Hashtable htRoles = null;
     if (Host.PerformanceSetting != Common.Globals.PerformanceSettings.NoCaching)
     {
         htRoles = (Hashtable)DataCache.GetCache("GetRoles");
     }
     if (htRoles == null)
     {
         RoleController objRoleController = new RoleController();
         ArrayList arrRoles;
         arrRoles = objRoleController.GetRoles();
         htRoles = new Hashtable();
         int i;
         for (i = 0; i <= arrRoles.Count - 1; i++)
         {
             RoleInfo objRole;
             objRole = (RoleInfo)arrRoles[i];
             htRoles.Add(objRole.RoleID, objRole.RoleName);
         }
         if (Host.PerformanceSetting != Common.Globals.PerformanceSettings.NoCaching)
         {
             DataCache.SetCache("GetRoles", htRoles);
         }
     }
     return Convert.ToString(htRoles[RoleID]);
 }
 private void ParsePortalDesktopModules(XPathNavigator nav, int portalID)
 {
     string friendlyName = Null.NullString;
     DesktopModuleInfo desktopModule = null;
     foreach (XPathNavigator desktopModuleNav in nav.Select("portalDesktopModule"))
     {
         friendlyName = XmlUtils.GetNodeValue(desktopModuleNav, "friendlyname");
         if (!string.IsNullOrEmpty(friendlyName))
         {
             desktopModule = DesktopModuleController.GetDesktopModuleByFriendlyName(friendlyName);
             if (desktopModule != null)
             {
                 DesktopModulePermissionCollection permissions = new DesktopModulePermissionCollection();
                 foreach (XPathNavigator permissionNav in desktopModuleNav.Select("portalDesktopModulePermissions/portalDesktopModulePermission"))
                 {
                     string code = XmlUtils.GetNodeValue(permissionNav, "permissioncode");
                     string key = XmlUtils.GetNodeValue(permissionNav, "permissionkey");
                     DesktopModulePermissionInfo desktopModulePermission = null;
                     ArrayList arrPermissions = new PermissionController().GetPermissionByCodeAndKey(code, key);
                     if (arrPermissions.Count > 0)
                     {
                         PermissionInfo permission = arrPermissions[0] as PermissionInfo;
                         if (permission != null)
                         {
                             desktopModulePermission = new DesktopModulePermissionInfo(permission);
                         }
                     }
                     desktopModulePermission.AllowAccess = bool.Parse(XmlUtils.GetNodeValue(permissionNav, "allowaccess"));
                     string rolename = XmlUtils.GetNodeValue(permissionNav, "rolename");
                     if (!string.IsNullOrEmpty(rolename))
                     {
                         RoleInfo role = new RoleController().GetRoleByName(portalID, rolename);
                         if (role != null)
                         {
                             desktopModulePermission.RoleID = role.RoleID;
                         }
                     }
                     permissions.Add(desktopModulePermission);
                 }
                 DesktopModuleController.AddDesktopModuleToPortal(portalID, desktopModule, permissions, false);
             }
         }
     }
 }
 private void ParseFolderPermissions(XmlNodeList nodeFolderPermissions, int PortalId, FolderInfo folder)
 {
     Security.Permissions.PermissionController objPermissionController = new Security.Permissions.PermissionController();
     Security.Permissions.FolderPermissionController objFolderPermissionController = new Security.Permissions.FolderPermissionController();
     RoleController objRoleController = new RoleController();
     int PermissionID = 0;
     folder.FolderPermissions.Clear();
     foreach (XmlNode xmlFolderPermission in nodeFolderPermissions)
     {
         string PermissionKey = XmlUtils.GetNodeValue(xmlFolderPermission.CreateNavigator(), "permissionkey");
         string PermissionCode = XmlUtils.GetNodeValue(xmlFolderPermission.CreateNavigator(), "permissioncode");
         string RoleName = XmlUtils.GetNodeValue(xmlFolderPermission.CreateNavigator(), "rolename");
         bool AllowAccess = XmlUtils.GetNodeValueBoolean(xmlFolderPermission, "allowaccess");
         foreach (PermissionInfo objPermission in objPermissionController.GetPermissionByCodeAndKey(PermissionCode, PermissionKey))
         {
             PermissionID = objPermission.PermissionID;
         }
         int RoleID = int.MinValue;
         switch (RoleName)
         {
             case Globals.glbRoleAllUsersName:
                 RoleID = Convert.ToInt32(Globals.glbRoleAllUsers);
                 break;
             case Common.Globals.glbRoleUnauthUserName:
                 RoleID = Convert.ToInt32(Globals.glbRoleUnauthUser);
                 break;
             default:
                 RoleInfo objRole = objRoleController.GetRoleByName(PortalId, RoleName);
                 if (objRole != null)
                 {
                     RoleID = objRole.RoleID;
                 }
                 break;
         }
         if (RoleID != int.MinValue)
         {
             FolderPermissionInfo objFolderPermission = new FolderPermissionInfo();
             objFolderPermission.FolderID = folder.FolderID;
             objFolderPermission.PermissionID = PermissionID;
             objFolderPermission.RoleID = RoleID;
             objFolderPermission.AllowAccess = AllowAccess;
             folder.FolderPermissions.Add(objFolderPermission);
         }
     }
     FolderPermissionController.SaveFolderPermissions(folder);
 }
 private void ParseRoleGroups(XPathNavigator nav, int portalID, int administratorId)
 {
     int administratorRoleId = -1;
     int registeredRoleId = -1;
     int subscriberRoleId = -1;
     RoleController controller = new RoleController();
     foreach (XPathNavigator roleGroupNav in nav.Select("rolegroup"))
     {
         RoleGroupInfo roleGroup = CBO.DeserializeObject<RoleGroupInfo>(new StringReader(roleGroupNav.OuterXml));
         if (roleGroup.RoleGroupName != "GlobalRoles")
         {
             roleGroup.PortalID = portalID;
             CreateRoleGroup(roleGroup);
         }
         foreach (RoleInfo role in roleGroup.Roles.Values)
         {
             role.PortalID = portalID;
             role.RoleGroupID = roleGroup.RoleGroupID;
             switch (role.RoleType)
             {
                 case RoleType.Administrator:
                     administratorRoleId = CreateRole(role);
                     break;
                 case RoleType.RegisteredUser:
                     registeredRoleId = CreateRole(role);
                     break;
                 case RoleType.Subscriber:
                     subscriberRoleId = CreateRole(role);
                     break;
                 case RoleType.None:
                     CreateRole(role);
                     break;
             }
         }
     }
     CreateDefaultPortalRoles(portalID, administratorId, administratorRoleId, registeredRoleId, subscriberRoleId);
     PortalInfo objportal;
     objportal = GetPortal(portalID);
     UpdatePortalSetup(portalID, administratorId, administratorRoleId, registeredRoleId, objportal.SplashTabId, objportal.HomeTabId, objportal.LoginTabId, objportal.RegisterTabId, objportal.UserTabId, objportal.AdminTabId, PortalController.GetActivePortalLanguage(portalID));
 }
 private void CreateRoleGroup(RoleGroupInfo roleGroup)
 {
     RoleGroupInfo objRoleGroupInfo;
     RoleController objRoleController = new RoleController();
     int roleGroupId = Null.NullInteger;
     objRoleGroupInfo = RoleController.GetRoleGroupByName(roleGroup.PortalID, roleGroup.RoleGroupName);
     if (objRoleGroupInfo == null)
     {
         roleGroup.RoleGroupID = RoleController.AddRoleGroup(roleGroup);
     }
     else
     {
         roleGroup.RoleGroupID = objRoleGroupInfo.RoleGroupID;
     }
 }
 public static bool DeleteUserRole(UserInfo objUser, RoleInfo objRole, PortalSettings PortalSettings, bool notifyUser)
 {
     RoleController objRoleController = new RoleController();
     bool canDelete = objRoleController.DeleteUserRole(PortalSettings.PortalId, objUser.UserID, objRole.RoleID);
     if (canDelete)
     {
         if (notifyUser)
         {
             SendNotification(objUser, objRole, PortalSettings, UserRoleActions.delete);
         }
     }
     return canDelete;
 }
 public static void UpdateRoleGroup(RoleGroupInfo roleGroup, bool includeRoles)
 {
     provider.UpdateRoleGroup(roleGroup);
     Services.Log.EventLog.EventLogController objEventLog = new Services.Log.EventLog.EventLogController();
     objEventLog.AddLog(roleGroup, PortalController.GetCurrentPortalSettings(), UserController.GetCurrentUserInfo().UserID, "", Services.Log.EventLog.EventLogController.EventLogType.USER_ROLE_UPDATED);
     if (includeRoles)
     {
         RoleController controller = new RoleController();
         foreach (RoleInfo role in roleGroup.Roles.Values)
         {
             controller.UpdateRole(role);
             objEventLog.AddLog(role, PortalController.GetCurrentPortalSettings(), UserController.GetCurrentUserInfo().UserID, "", Services.Log.EventLog.EventLogController.EventLogType.ROLE_UPDATED);
         }
     }
 }
        public CascadingDropDownNameValue[] GetRoleList(string knownCategoryValues, string category)
        {
            StringDictionary dataValues = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
            string ApplicationId = dataValues["ApplicationId"];
            RoleController role_obj = new RoleController();
            DataTable dt = role_obj.GetRoleListByApplicationId(ApplicationId);

            List<CascadingDropDownNameValue> role_list = new List<CascadingDropDownNameValue>();
            foreach (DataRow dRow in dt.Rows)
            {
                string RoleId = dRow["RoleId"].ToString();
                string RoleName = dRow["RoleName"].ToString();
                role_list.Add(new CascadingDropDownNameValue(RoleName, RoleId));
            }
            return role_list.ToArray();
        }
 public static UserCreateStatus CreateUser(ref UserInfo objUser)
 {
     UserCreateStatus createStatus = UserCreateStatus.AddUser;
     createStatus = memberProvider.CreateUser(ref objUser);
     if (createStatus == UserCreateStatus.Success)
     {
         Services.Log.EventLog.EventLogController objEventLog = new Services.Log.EventLog.EventLogController();
         objEventLog.AddLog(objUser, PortalController.GetCurrentPortalSettings(), UserController.GetCurrentUserInfo().UserID, "", Services.Log.EventLog.EventLogController.EventLogType.USER_CREATED);
         DataCache.ClearPortalCache(objUser.PortalID, false);
         if (!objUser.IsSuperUser)
         {
             RoleController objRoles = new RoleController();
             RoleInfo objRole;
             ArrayList arrRoles = objRoles.GetPortalRoles(objUser.PortalID);
             int i;
             for (i = 0; i <= arrRoles.Count - 1; i++)
             {
                 objRole = (RoleInfo)arrRoles[i];
                 if (objRole.AutoAssignment == true)
                 {
                     objRoles.AddUserRole(objUser.PortalID, objUser.UserID, objRole.RoleID, Null.NullDate, Null.NullDate);
                 }
             }
         }
     }
     return createStatus;
 }
 private void CreateDefaultPortalRoles(int portalId, int administratorId, int administratorRoleId, int registeredRoleId, int subscriberRoleId)
 {
     RoleController controller = new RoleController();
     if (administratorRoleId == -1)
     {
         administratorRoleId = CreateRole(portalId, "Administrators", "Portal Administrators", 0, 0, "M", 0, 0, "N", false,
         false);
     }
     if (registeredRoleId == -1)
     {
         registeredRoleId = CreateRole(portalId, "Registered Users", "Registered Users", 0, 0, "M", 0, 0, "N", false,
         true);
     }
     if (subscriberRoleId == -1)
     {
         subscriberRoleId = CreateRole(portalId, "Subscribers", "A public role for portal subscriptions", 0, 0, "M", 0, 0, "N", true,
         true);
     }
     controller.AddUserRole(portalId, administratorId, administratorRoleId, Null.NullDate, Null.NullDate);
     controller.AddUserRole(portalId, administratorId, registeredRoleId, Null.NullDate, Null.NullDate);
     controller.AddUserRole(portalId, administratorId, subscriberRoleId, Null.NullDate, Null.NullDate);
 }