当前位置: 首页>>代码示例>>C#>>正文


C# RoleController.GetRoleByName方法代码示例

本文整理汇总了C#中DotNetNuke.Security.Roles.RoleController.GetRoleByName方法的典型用法代码示例。如果您正苦于以下问题:C# RoleController.GetRoleByName方法的具体用法?C# RoleController.GetRoleByName怎么用?C# RoleController.GetRoleByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DotNetNuke.Security.Roles.RoleController的用法示例。


在下文中一共展示了RoleController.GetRoleByName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GivenThereIsAPageCalled

        public void GivenThereIsAPageCalled(string pageName, Table permissions)
        {
            var reset = false;
            var tabController = new TabController();
            var tab = tabController.GetTabByName(pageName, PortalId);
            if (tab == null)
            {
                tab = new TabInfo
                {
                    TabName = pageName,
                    PortalID = 0
                };
                tab.TabID = tabController.AddTab(tab);
                foreach (var row in permissions.Rows)
                {
                    var roleId = -1;
                    var roleController = new RoleController();
                    if (row[0] == "All Users")
                    {
                        roleId = -1;
                    }
                    else
                    {
                        var role = roleController.GetRoleByName(PortalId, row[0]);
                        if (role == null)
                        {
                            if (roleController.GetRoleByName(Null.NullInteger, row[0]) == null)
                            {
                                role = new RoleInfo { RoleName = row[0], RoleGroupID = Null.NullInteger };
                                roleId = roleController.AddRole(role);
                            }
                        }
                    }
                    var permissionController = new PermissionController();
                    var permission = permissionController.GetPermissionByCodeAndKey("SYSTEM_TAB", row[1]);
                    var tabPermission = new TabPermissionInfo
                    {
                        PermissionID = 3,
                        TabID = tab.TabID,
                        AllowAccess = true,
                        RoleID = roleId
                    };
                    tab.TabPermissions.Add(tabPermission);
                }

                tabController.UpdateTab(tab);
                reset = true;
            }
            Page = tab;
            if (reset)
            {
                Config.Touch();
            }
        }
开发者ID:biganth,项目名称:Curt,代码行数:54,代码来源:PageSteps.cs

示例2: AddClientEditorRole

 public void AddClientEditorRole()
 {
     if (_userInfo != null)
     {
         if (!_userInfo.IsInRole(StoreSettings.ClientEditorRole))
         {
             var rc = new DotNetNuke.Security.Roles.RoleController();
             var ri = rc.GetRoleByName(PortalId, StoreSettings.ClientEditorRole);
             if (ri != null) rc.AddUserRole(PortalId, _userInfo.UserID, ri.RoleID, Null.NullDate, Null.NullDate);
             if (StoreSettings.Current.Get("sendclientroleemail") == "True") NBrightBuyUtils.SendEmail(_userInfo.Email, "addclientrole.html", _clientInfo, "", "", _userInfo.Profile.PreferredLocale);
         }
     }
 }
开发者ID:DNNMonster,项目名称:NBrightBuy,代码行数:13,代码来源:ClientData.cs

示例3: CreateStaffMember

    public static AP_StaffBroker_Staff CreateStaffMember(int PortalId, DotNetNuke.Entities.Users.UserInfo User1in, string SpouseName, DateTime SpouseDOB, short staffTypeIn = 1)
    {
        DotNetNuke.Security.Roles.RoleController rc = new DotNetNuke.Security.Roles.RoleController();
        if (rc.GetRoleByName(PortalId, "Staff") == null)
        {
            DotNetNuke.Security.Roles.RoleInfo insert = new DotNetNuke.Security.Roles.RoleInfo();
            insert.Description = "Staff Members";
            insert.RoleName = "Staff";
            insert.AutoAssignment = false;
            insert.IsPublic = false;
            insert.RoleGroupID = -1;
            insert.PortalID = PortalId;
            rc.AddRole(insert);
        }

        rc.AddUserRole(PortalId, User1in.UserID, rc.GetRoleByName(PortalId, "Staff").RoleID, DateTime.MaxValue);

        StaffBrokerDataContext d = new StaffBrokerDataContext();
        var searchStaff = from c in d.AP_StaffBroker_Staffs where c.Active && (c.UserId1 == User1in.UserID || c.UserId2 == User1in.UserID) select c;
        if (searchStaff.Count() > 0)
            return searchStaff.First();
        //Create Married to Non-Staff
        AP_StaffBroker_Staff rtn = new AP_StaffBroker_Staff();
        rtn.UserId1 = User1in.UserID;
        rtn.UserId2 = -1;
        rtn.DisplayName = User1in.FirstName + " " + User1in.LastName;

        rtn.StaffTypeId = staffTypeIn;
        rtn.CostCenter = "";
        rtn.PortalId = PortalId;
        rtn.Active = true;
        d.AP_StaffBroker_Staffs.InsertOnSubmit(rtn);
        d.SubmitChanges();
        //Now add Spouse data
        AddProfileValue(PortalId, rtn.StaffId, "SpouseDOB", SpouseDOB.ToShortDateString());
        AddProfileValue(PortalId, rtn.StaffId, "SpouseName", SpouseName);

        return rtn;
    }
开发者ID:GlobalTechnology,项目名称:OpsInABox,代码行数:39,代码来源:StaffBrokerFunctions.cs

示例4: Save_Click

        private void Save_Click(object sender, EventArgs e)
        {
            if (GroupId > 0)
            {
                RoleController roleController = new RoleController();
                Security.PortalSecurity ps = new Security.PortalSecurity();

                txtGroupName.Text = ps.InputFilter(txtGroupName.Text, Security.PortalSecurity.FilterFlag.NoScripting);
                txtGroupName.Text = ps.InputFilter(txtGroupName.Text, Security.PortalSecurity.FilterFlag.NoMarkup);
                txtDescription.Text = ps.InputFilter(txtDescription.Text, Security.PortalSecurity.FilterFlag.NoScripting);
                txtDescription.Text = ps.InputFilter(txtDescription.Text, Security.PortalSecurity.FilterFlag.NoMarkup);
                
                var roleInfo = roleController.GetRole(GroupId, PortalId);
                if (roleInfo != null)
                {

                    if (txtGroupName.Visible) //if this is visible assume that we're editing the groupname
                    {
                        if (txtGroupName.Text != roleInfo.RoleName)
                        {
                            if (roleController.GetRoleByName(PortalId, txtGroupName.Text) != null)
                            {
                                lblInvalidGroupName.Visible = true;
                                return;
                            }
                        }
                    }

                    if(!roleInfo.IsSystemRole)
                    {
                        roleInfo.RoleName = txtGroupName.Text;
                    }
                    
                    roleInfo.Description = txtDescription.Text;
                    roleInfo.IsPublic = rdAccessTypePublic.Checked;

                    if (roleInfo.Settings.ContainsKey("ReviewMembers"))
                        roleInfo.Settings["ReviewMembers"] = chkMemberApproved.Checked.ToString();
                    else
                        roleInfo.Settings.Add("ReviewMembers", chkMemberApproved.Checked.ToString());
                    
                    TestableRoleController.Instance.UpdateRoleSettings(roleInfo, true);
                    roleController.UpdateRole(roleInfo);

                    if (inpFile.PostedFile.ContentLength > 0)
                    {
                        IFileManager _fileManager = FileManager.Instance;
                        IFolderManager _folderManager = FolderManager.Instance;
                        var rootFolderPath = PathUtils.Instance.FormatFolderPath(PortalSettings.HomeDirectory);

                        IFolderInfo groupFolder = _folderManager.GetFolder(PortalSettings.PortalId, "Groups/" + roleInfo.RoleID);
                        if (groupFolder == null)
                        {
                            groupFolder = _folderManager.AddFolder(PortalSettings.PortalId, "Groups/" + roleInfo.RoleID);
                        }
                        if (groupFolder != null)
                        {
                            var fileName = Path.GetFileName(inpFile.PostedFile.FileName);
                            var fileInfo = _fileManager.AddFile(groupFolder, fileName, inpFile.PostedFile.InputStream, true);
                            roleInfo.IconFile = "FileID=" + fileInfo.FileId;
                            roleController.UpdateRole(roleInfo);
                        }
                    }

                    //Clear Roles Cache
                    DataCache.RemoveCache("GetRoles");

                }

                Response.Redirect(Globals.NavigateURL(TabId, "", new String[] { "groupid=" + GroupId.ToString() }));
            }
        }
开发者ID:rut5949,项目名称:Dnn.Platform,代码行数:72,代码来源:GroupEdit.ascx.cs

示例5: Create_Click

        private void Create_Click(object sender, EventArgs e)
        {
            RoleController roleController = new RoleController();
            Security.PortalSecurity ps = new Security.PortalSecurity();
            txtGroupName.Text = ps.InputFilter(txtGroupName.Text, Security.PortalSecurity.FilterFlag.NoScripting);
            txtGroupName.Text = ps.InputFilter(txtGroupName.Text, Security.PortalSecurity.FilterFlag.NoMarkup);

            txtDescription.Text = ps.InputFilter(txtDescription.Text, Security.PortalSecurity.FilterFlag.NoScripting);
            txtDescription.Text = ps.InputFilter(txtDescription.Text, Security.PortalSecurity.FilterFlag.NoMarkup);
            if (roleController.GetRoleByName(PortalId, txtGroupName.Text) != null)
            {
                reqGroupName.Visible = true;
                return;
            }
            List<RoleInfo> modRoles = new List<RoleInfo>();
            foreach (ModulePermissionInfo modulePermissionInfo in ModulePermissionController.GetModulePermissions(ModuleId, TabId))
            {
                if (modulePermissionInfo.PermissionKey == "MODGROUP" && modulePermissionInfo.AllowAccess)
                {
                    modRoles.Add(roleController.GetRole(modulePermissionInfo.RoleID, PortalId));
                }
            }
            RoleInfo roleInfo = new RoleInfo()
            {
                PortalID = PortalId,
                RoleName = txtGroupName.Text,
                Description = txtDescription.Text,
                SecurityMode = SecurityMode.SocialGroup,
                Status = RoleStatus.Approved,
                IsPublic = rdAccessTypePublic.Checked
            };
            var userRoleStatus = RoleStatus.Pending;
            if (GroupModerationEnabled)
            {
                roleInfo.Status = RoleStatus.Pending;
                userRoleStatus = RoleStatus.Pending;
            }
            else
            {
                userRoleStatus = RoleStatus.Approved;
            }

            var objModulePermissions = new ModulePermissionCollection(CBO.FillCollection(DataProvider.Instance().GetModulePermissionsByModuleID(ModuleId, -1), typeof(ModulePermissionInfo)));
            if (ModulePermissionController.HasModulePermission(objModulePermissions, "MODGROUP"))
            {
                roleInfo.Status = RoleStatus.Approved;
                userRoleStatus = RoleStatus.Approved;
            }
            roleInfo.RoleGroupID = DefaultRoleGroupId;

            roleInfo.RoleID = roleController.AddRole(roleInfo);
            roleInfo = roleController.GetRole(roleInfo.RoleID, PortalId);
            roleInfo.Settings.Add("URL", Globals.NavigateURL(GroupViewTabId, "", new String[] { "groupid=" + roleInfo.RoleID.ToString() }));
            roleInfo.Settings.Add("GroupCreatorName", UserInfo.DisplayName);
            roleInfo.Settings.Add("ReviewMembers", chkMemberApproved.Checked.ToString());

            TestableRoleController.Instance.UpdateRoleSettings(roleInfo, true);
            if (inpFile.PostedFile.ContentLength > 0)
            {
                IFileManager _fileManager = FileManager.Instance;
                IFolderManager _folderManager = FolderManager.Instance;
                var rootFolderPath = PathUtils.Instance.FormatFolderPath(PortalSettings.HomeDirectory);

                IFolderInfo groupFolder = _folderManager.GetFolder(PortalSettings.PortalId, "Groups/" + roleInfo.RoleID);
                if (groupFolder == null)
                {
                    groupFolder = _folderManager.AddFolder(PortalSettings.PortalId, "Groups/" + roleInfo.RoleID);
                }
                if (groupFolder != null)
                {
                    var fileName = Path.GetFileName(inpFile.PostedFile.FileName);
                    var fileInfo = _fileManager.AddFile(groupFolder, fileName, inpFile.PostedFile.InputStream, true);
                    roleInfo.IconFile = "FileID=" + fileInfo.FileId;
                    roleController.UpdateRole(roleInfo);
                }
            }

            Components.Notifications notifications = new Components.Notifications();


            roleController.AddUserRole(PortalId, UserId, roleInfo.RoleID, userRoleStatus, true, Null.NullDate, Null.NullDate);
            if (roleInfo.Status == RoleStatus.Pending)
            {
                //Send notification to Group Moderators to approve/reject group.
                notifications.AddGroupNotification(Constants.GroupPendingNotification, GroupViewTabId, ModuleId, roleInfo, UserInfo, modRoles);
            }
            else
            {
                //Send notification to Group Moderators informing of new group.
                notifications.AddGroupNotification(Constants.GroupCreatedNotification, GroupViewTabId, ModuleId, roleInfo, UserInfo, modRoles);

                //Add entry to journal.
                GroupUtilities.CreateJournalEntry(roleInfo, UserInfo);
            }

            Response.Redirect(Globals.NavigateURL(GroupViewTabId, "", new String[] { "groupid=" + roleInfo.RoleID.ToString() }));
        }
开发者ID:biganth,项目名称:Curt,代码行数:97,代码来源:Create.ascx.cs

示例6: CreateGroupForum

		public int CreateGroupForum(int portalId, int moduleId, int socialGroupId, int forumGroupId, string forumName, string forumDescription, bool isPrivate, string forumConfig)
		{
			var forumId = -1;

			try
			{
				var rc = new RoleController();
				var forumsDb = new Data.Common();
			    var fgc = new ForumGroupController();
				var gi = fgc.Groups_Get(moduleId, forumGroupId);
				var socialGroup = rc.GetRole(socialGroupId, portalId);
				var groupAdmin = socialGroupId.ToString() + ":0";
				var groupMember = socialGroupId.ToString();

			    var ri = rc.GetRoleByName(portalId, "Administrators");
				var permissionsId = forumsDb.CreatePermSet(ri.RoleID.ToString());

				moduleId = gi.ModuleId;

				var fi = new Forum
				{
				    ForumDesc = forumDescription,
				    Active = true,
				    ForumGroupId = forumGroupId,
				    ForumID = -1,
				    ForumName = forumName,
				    Hidden = isPrivate,
				    ModuleId = gi.ModuleId,
				    ParentForumId = 0,
				    PortalId = portalId,
				    PermissionsId = gi.PermissionsId,
				    SortOrder = 0,
				    SocialGroupId = socialGroupId
				};

			    forumId = Forums_Save(portalId, fi, true, true);
				fi = GetForum(portalId, moduleId, forumId);
				fi.PermissionsId = permissionsId;
				Forums_Save(portalId, fi, false, false);

			    var xDoc = new XmlDocument();
				xDoc.LoadXml(forumConfig);

				var xRoot = xDoc.DocumentElement;
			    if (xRoot != null)
			    {
			        var xSecList = xRoot.SelectSingleNode("//security[@type='groupadmin']");
			        string permSet;
			        string secKey;
			        if (xSecList != null)
			        {
			            foreach (XmlNode n in xSecList.ChildNodes)
			            {
			                secKey = n.Name;
			                if (n.Attributes == null || n.Attributes["value"].Value != "true") 
			                    continue;
			                permSet = forumsDb.GetPermSet(permissionsId, secKey);
			                permSet = Permissions.AddPermToSet(groupAdmin, 2, permSet);
			                forumsDb.SavePermSet(permissionsId, secKey, permSet);
			            }
			        }

			        xSecList = xRoot.SelectSingleNode("//security[@type='groupmember']");
			        if (xSecList != null)
			        {
			            foreach (XmlNode n in xSecList.ChildNodes)
			            {
			                secKey = n.Name;
						    
			                if (n.Attributes == null || n.Attributes["value"].Value != "true") 
			                    continue;
						    
			                permSet = forumsDb.GetPermSet(permissionsId, secKey);
			                permSet = Permissions.AddPermToSet(groupMember, 0, permSet);
			                forumsDb.SavePermSet(permissionsId, secKey, permSet);
			            }
			        }

			        if (socialGroup.IsPublic)
			        {
			            xSecList = xRoot.SelectSingleNode("//security[@type='registereduser']");
			            ri = rc.GetRoleByName(portalId, "Registered Users");
			            if (xSecList != null)
			            {
			                foreach (XmlNode n in xSecList.ChildNodes)
			                {
			                    secKey = n.Name;
							    
			                    if (n.Attributes == null || n.Attributes["value"].Value != "true") 
			                        continue;
							    
			                    permSet = forumsDb.GetPermSet(permissionsId, secKey);
			                    permSet = Permissions.AddPermToSet(ri.RoleID.ToString(), 0, permSet);
			                    forumsDb.SavePermSet(permissionsId, secKey, permSet);
			                }
			            }

			            xSecList = xRoot.SelectSingleNode("//security[@type='anon']");
			            if (xSecList != null)
			            {
//.........这里部分代码省略.........
开发者ID:allanedk,项目名称:ActiveForums,代码行数:101,代码来源:ForumController.cs

示例7: OnUpdateClick

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// cmdUpdate_Click runs when the update Button is clicked
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// 	[cnurse]	9/10/2004	Updated to reflect design changes for Help, 508 support
        ///                       and localisation
        /// 	[jlucarino]	2/23/2009	Added CreatedByUserID and LastModifiedByUserID
        /// </history>
        /// -----------------------------------------------------------------------------
        protected void OnUpdateClick(object sender, EventArgs e)
        {
            try
            {
                if (Page.IsValid)
                {
                    float sglServiceFee = 0;
                    var intBillingPeriod = 1;
                    var strBillingFrequency = "N";

                    if (cboBillingFrequency.SelectedItem.Value == "N" && !String.IsNullOrEmpty(txtServiceFee.Text))
                    {
                        UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("IncompatibleFee", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                        return;
                    }
                    if (!String.IsNullOrEmpty(txtServiceFee.Text) && !String.IsNullOrEmpty(txtBillingPeriod.Text) && cboBillingFrequency.SelectedItem.Value != "N")
                    {
                        sglServiceFee = float.Parse(txtServiceFee.Text);
                        intBillingPeriod = int.Parse(txtBillingPeriod.Text);
                        strBillingFrequency = cboBillingFrequency.SelectedItem.Value;
                    }
                    float sglTrialFee = 0;
                    var intTrialPeriod = 1;
                    var strTrialFrequency = "N";

                    if (sglServiceFee != 0 && !String.IsNullOrEmpty(txtTrialFee.Text) && !String.IsNullOrEmpty(txtTrialPeriod.Text) && cboTrialFrequency.SelectedItem.Value != "N")
                    {
                        sglTrialFee = float.Parse(txtTrialFee.Text);
                        intTrialPeriod = int.Parse(txtTrialPeriod.Text);
                        strTrialFrequency = cboTrialFrequency.SelectedItem.Value;
                    }
                    var objRoleController = new RoleController();
                    var objRoleInfo = new RoleInfo();
                    objRoleInfo.PortalID = PortalId;
                    objRoleInfo.RoleID = _roleID;
                    objRoleInfo.RoleGroupID = int.Parse(cboRoleGroups.SelectedValue);
                    objRoleInfo.RoleName = txtRoleName.Text;
                    objRoleInfo.Description = txtDescription.Text;
                    objRoleInfo.ServiceFee = sglServiceFee;
                    objRoleInfo.BillingPeriod = intBillingPeriod;
                    objRoleInfo.BillingFrequency = strBillingFrequency;
                    objRoleInfo.TrialFee = sglTrialFee;
                    objRoleInfo.TrialPeriod = intTrialPeriod;
                    objRoleInfo.TrialFrequency = strTrialFrequency;
                    objRoleInfo.IsPublic = chkIsPublic.Checked;
                    objRoleInfo.AutoAssignment = chkAutoAssignment.Checked;
                    objRoleInfo.RSVPCode = txtRSVPCode.Text;
                    objRoleInfo.IconFile = ctlIcon.Url;
                    if (_roleID == -1)
                    {
                        if (objRoleController.GetRoleByName(PortalId, objRoleInfo.RoleName) == null)
                        {
                            objRoleController.AddRole(objRoleInfo);
                        }
                        else
                        {
                            UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("DuplicateRole", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                            return;
                        }
                    }
                    else
                    {
                        objRoleController.UpdateRole(objRoleInfo);
                    }
					
                    //Clear Roles Cache
                    DataCache.RemoveCache("GetRoles");

                    Response.Redirect(Globals.NavigateURL());
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
开发者ID:marceltoben,项目名称:evandrix.github.com,代码行数:88,代码来源:EditRoles.ascx.cs

示例8: ParseFolderPermissions

        /// <summary>
        /// Parses folder permissions
        /// </summary>
        /// <param name="nodeFolderPermissions">Node for folder permissions</param>
        /// <param name="PortalID">PortalId of new portal</param>
        /// <param name="FolderId">FolderId of folder being processed</param>
        /// <history>
        /// 	[cnurse]	11/09/2004	Created
        /// </history>
        private void ParseFolderPermissions( XmlNodeList nodeFolderPermissions, int PortalID, int FolderId, string folderPath )
        {
            FolderPermissionCollection objFolderPermissions = new FolderPermissionCollection();
            PermissionController objPermissionController = new PermissionController();
            PermissionInfo objPermission = null;
            FolderPermissionController objFolderPermissionController = new FolderPermissionController();
            RoleController objRoleController = new RoleController();
            RoleInfo objRole = null;
            int RoleID = 0;
            int PermissionID = 0;
            string PermissionKey = null;
            string PermissionCode = null;
            string RoleName = null;
            bool AllowAccess = false;
            ArrayList arrPermissions = null;
            int i = 0;

            foreach( XmlNode xmlFolderPermission in nodeFolderPermissions )
            {
                PermissionKey = XmlUtils.GetNodeValue( xmlFolderPermission, "permissionkey", "" );
                PermissionCode = XmlUtils.GetNodeValue( xmlFolderPermission, "permissioncode", "" );
                RoleName = XmlUtils.GetNodeValue( xmlFolderPermission, "rolename", "" );
                AllowAccess = XmlUtils.GetNodeValueBoolean( xmlFolderPermission, "allowaccess", false );
                arrPermissions = objPermissionController.GetPermissionByCodeAndKey( PermissionCode, PermissionKey );

                for( i = 0; i < arrPermissions.Count; i++ )
                {
                    objPermission = (PermissionInfo)( arrPermissions[i] );
                    PermissionID = objPermission.PermissionID;
                }
                RoleID = int.MinValue;
                if( RoleName == Globals.glbRoleAllUsersName )
                {
                    RoleID = Convert.ToInt32( Globals.glbRoleAllUsers );
                }
                else if( RoleName == Globals.glbRoleUnauthUserName )
                {
                    RoleID = Convert.ToInt32( Globals.glbRoleUnauthUser );
                }
                else
                {
                    objRole = objRoleController.GetRoleByName( PortalID, RoleName );
                    if( objRole != null )
                    {
                        RoleID = objRole.RoleID;
                    }
                }

                // if role was found add, otherwise ignore
                if( RoleID != int.MinValue )
                {
                    if( AllowAccess )
                    {
                        FileSystemUtils.SetFolderPermission( PortalID, FolderId, PermissionID, RoleID, folderPath );
                    }
                }
            }
        }
开发者ID:huayang912,项目名称:cs-dotnetnuke,代码行数:67,代码来源:PortalController.cs

示例9: Roles_AddRemove

        public HttpResponseMessage Roles_AddRemove(int userid, string role, string mode)
        {

            int v_Current_Portal_ID = this.ActiveModule.PortalID;

            //Getting user info
            DotNetNuke.Entities.Users.UserInfo v_UserInfo = DotNetNuke.Entities.Users.UserController.GetUserById(v_Current_Portal_ID, userid);

            if (v_UserInfo != null)
            {

                RoleController v_RoleController = new RoleController();
                RoleInfo v_RoleInfo = v_RoleController.GetRoleByName(v_Current_Portal_ID, role);

                if (v_RoleInfo != null)
                {

                    if (v_UserInfo.IsInRole(v_RoleInfo.RoleName) && mode == "remove")
                    {
                        RoleController.DeleteUserRole(v_UserInfo, v_RoleInfo, this.PortalSettings, false);
                        return Request.CreateResponse(HttpStatusCode.OK, "ok role removed");
                    }

                    if (v_UserInfo.IsInRole(v_RoleInfo.RoleName) == false && mode == "add")
                    {

                        v_RoleController.AddUserRole(v_Current_Portal_ID, userid, v_RoleInfo.RoleID, DateTime.MinValue);
                        return Request.CreateResponse(HttpStatusCode.OK, "ok role added");
                    }

                }
                else
                {

                    return Request.CreateResponse(HttpStatusCode.InternalServerError, "No such role with that RoleName");

                }

            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, "No such user with that Id");
            }

            return Request.CreateResponse(HttpStatusCode.OK, "ok");

        }
开发者ID:joinsaturn,项目名称:UManage,代码行数:47,代码来源:WebApiController.cs

示例10: btnSubmitAnswers_Click


//.........这里部分代码省略.........
                                   QuizId = _quizId,
                                   ReminderSent = false,
                                   UserId = UserId,
                                   UserIpAddress = Request.UserHostAddress
                               };

            //Declare placeholder for the result it
            int resultId;

            //Did they pass
            if (oResults.Percentage >= oQuizInfo.PassPercentage)
            {
                oResults.Passed = true;
                oResults.ExpirationDate = oQuizInfo.CanExpire
                                              ? DateTime.Now.AddDays(oQuizInfo.ExpireDuration)
                                              : DateTime.Now.AddYears(10);

                //Now save it
                resultId = QuizController.SaveUserQuizResults(oResults);

                var certificate = Globals.NavigateURL("QuizCert", "mid=" + ModuleId,
                                                      "quizId=" + UrlUtils.EncryptParameter(_quizId.ToString()),
                                                      "exp=" +
                                                      UrlUtils.EncryptParameter(
                                                          Server.UrlEncode(
                                                              oResults.ExpirationDate.ToShortDateString())),
                                                      "resId=" + resultId);
                var noSkinQsParams =
                    "&SkinSrc=[G]Skins%2f_default%2fNo+Skin&ContainerSrc=[G]Containers%2f_default%2fNo+Container";

                //Setup pass notification
                var notification = new StringBuilder(Localization.GetString("PassTemplate", LocalResourceFile));
                notification.Append(Localization.GetString("ReturnLinkTemplate", LocalResourceFile));
                notification.Replace("[YOURSCORE]", Math.Round(oResults.Percentage, 0).ToString());
                notification.Replace("[REQUIREDSCORE]",
                                     Math.Round(oQuizInfo.PassPercentage, 0).ToString());
                notification.Replace("[CERTLINK]", certificate);
                notification.Replace("[CERTLINKPRINT]", certificate + noSkinQsParams);
                notification.Replace("[RETURNLINK]", Globals.NavigateURL(TabId));
                lblStatus.Text = notification.ToString();

                //Add to role if needed
                if (!oQuizInfo.RoleToAdd.Equals("-1"))
                {
                    var oRoleController = new RoleController();
                    var oRoleToAdd = oRoleController.GetRoleByName(PortalId, oQuizInfo.RoleToAdd);
                    if (oRoleToAdd != null)
                    {
                        oRoleController.AddUserRole(PortalId, UserId, oRoleToAdd.RoleID,
                                                    oQuizInfo.CanExpire
                                                        ? DateTime.Now.AddDays(oQuizInfo.ExpireDuration)
                                                        : Null.NullDate);
                    }
                    else
                        Exceptions.LogException(
                            new ArgumentException("Unable to add role, unable to find " + oQuizInfo.RoleName +
                                                  " role for assignment"));
                }
            }
            else
            {
                oResults.Passed = false;
                oResults.ExpirationDate = Null.NullDate;

                //Now save it
                resultId = QuizController.SaveUserQuizResults(oResults);

                //Setup fail notification
                var takeQuizLink = Globals.NavigateURL("TakeQuiz", "mid=" + ModuleId,
                                                       "quizId=" + UrlUtils.EncryptParameter(_quizId.ToString()));
                var notification = new StringBuilder(Localization.GetString("FailTemplate", LocalResourceFile));
                notification.Append(Localization.GetString("ReturnLinkTemplate", LocalResourceFile));
                notification.Replace("[YOURSCORE]", Math.Round(oResults.Percentage, 0).ToString());
                notification.Replace("[REQUIREDSCORE]",
                                     Math.Round(oQuizInfo.PassPercentage, 0).ToString());
                notification.Replace("[TESTLINK]", takeQuizLink);
                notification.Replace("[RETURNLINK]", Globals.NavigateURL(TabId));
                lblStatus.Text = notification.ToString();

                //Setup the re-take link
                btnTakeAgain.NavigateUrl = takeQuizLink;
                btnTakeAgain.Visible = true;
            }

            //Hide the submit button
            btnSubmitAnswers.Visible = false;

            //Now, we need to save the question answers
            foreach (UserQuestionAnswerInfo oAnswer in _answers)
            {
                oAnswer.ResultId = resultId;
                QuizController.SaveUserQuestionAnswer(oAnswer);
            }

            //Now, flag for rebinding
            _questionIndex = 0;
            _finished = true;

            BindAndDisplayQuestions(_quizId);
        }
开发者ID:IowaComputerGurus,项目名称:icg.dnn.quiz,代码行数:101,代码来源:TakeQuiz.ascx.cs

示例11: btnSynStu_Click

        const int TimeOut = 3600; // 1 hour

        #endregion Fields

        #region Methods

        protected void btnSynStu_Click(object sender, EventArgs e)
        {
            // Prepare for longtime jobs
            Server.ScriptTimeout = TimeOut;

            // Get list of all students
            var allStus = SqlHelper.ExecuteDataset(Config.GetConnectionString(), CommandType.Text, "SELECT StuId, StuNm, BDay, Email FROM Student").Tables[0];
            int total = allStus.Rows.Count;
            lblStuTotal.Text = total.ToString();
            // Count all students
            var allStuIds = (from r in allStus.Rows.Cast<DataRow>()
                             select (string)r["StuId"]).ToList();
            // Get StuId with profile
            var allStuInfos = (from r in allStus.Rows.Cast<DataRow>()
                               select r).ToDictionary(
                               r => (string)r["StuId"],
                               r => new
                               {
                                   Name = r["StuNm"] == DBNull.Value ? null : (string)r["StuNm"],
                                   BDay = r["BDay"] == DBNull.Value ? null : (DateTime?)r["BDay"],
                                   Email = r["Email"] == DBNull.Value ? null : (string)r["Email"],
                               });

            // Count registered students
            var roleCtlr = new RoleController();
            var roleId = roleCtlr.GetRoleByName(PortalId, "Student").RoleID;
            var regStus = SqlHelper.ExecuteDataset(Config.GetConnectionString(), CommandType.Text,
                string.Format("SELECT Users.Username FROM UserRoles INNER JOIN Users ON UserRoles.UserID = Users.UserID WHERE (UserRoles.RoleID = {0})", roleId)).Tables[0]; ;
            var regStuIds = (from u in regStus.Rows.Cast<DataRow>()
                             select (string)u["Username"]).ToList();

            // Count free students
            var freeStuIds = allStuIds.Except(regStuIds).ToArray();
            foreach (var stuid in freeStuIds)
            {
                var userinfo = new UserInfo
                {
                    PortalID = PortalId,
                    Username = stuid,
                    DisplayName = allStuInfos[stuid].Name,
                    FullName = allStuInfos[stuid].Name,
                    Email = allStuInfos[stuid].Email,
                };
                if (allStuInfos[stuid].BDay.HasValue)
                    userinfo.Membership.Password = string.Format("{0}{1}", stuid, allStuInfos[stuid].BDay.Value.Year % 100);
                else
                    userinfo.Membership.Password = stuid;
                var status = UserController.CreateUser(ref userinfo);
                if (status == UserCreateStatus.UserAlreadyRegistered)
                {
                    var userid = UserController.GetUserByName(PortalId, stuid).UserID;
                    // Add user to Student role
                    roleCtlr.AddUserRole(PortalId, userid, roleId, DateTime.MinValue);
                    regStuIds.Add(stuid);
                }
                else if (status == UserCreateStatus.Success)
                {
                    // Add user to Student role
                    roleCtlr.AddUserRole(PortalId, userinfo.UserID, roleId, DateTime.MaxValue);
                    regStuIds.Add(stuid);
                }
            }

            int no_reg = regStuIds.Count();
            lblNoRegStu.Text = no_reg.ToString();
            int no_free = total - no_reg;
            lblNoFreeStu.Text = no_free.ToString();
            freeStuIds = allStuIds.Except(regStuIds).ToArray();
            lblFreeStus.Text = string.Join(", ", freeStuIds);
        }
开发者ID:hoaian89,项目名称:DAA,代码行数:76,代码来源:StudentSyn.ascx.cs

示例12: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            // Show statistic
            if (!Page.IsPostBack)
            {
                // Get list of all students
                var allStus = SqlHelper.ExecuteDataset(Config.GetConnectionString(), CommandType.Text, "SELECT StuId FROM Student").Tables[0];
                // Count all students
                int total = allStus.Rows.Count;
                var allStuIds = from r in allStus.Rows.Cast<DataRow>()
                                select (string)r["StuId"];
                lblStuTotal.Text = total.ToString();

                // Count registered students
                var roleCtlr = new RoleController();
                var roleId = roleCtlr.GetRoleByName(PortalId, "Student").RoleID;
                var regStus = SqlHelper.ExecuteDataset(Config.GetConnectionString(), CommandType.Text,
                    string.Format("SELECT Users.Username FROM UserRoles INNER JOIN Users ON UserRoles.UserID = Users.UserID WHERE (UserRoles.RoleID = {0})", roleId)).Tables[0]; ;

                int no_reg = regStus.Rows.Count;
                var regStuIds = from u in regStus.Rows.Cast<DataRow>()
                                select (string)u["Username"];
                lblNoRegStu.Text = no_reg.ToString();

                // Count free students
                int no_free = total - no_reg;
                var freeStuIds = allStuIds.Except(regStuIds).ToArray();
                lblNoFreeStu.Text = no_free.ToString();
                lblFreeStus.Text = string.Join(", ", freeStuIds);
            }
        }
开发者ID:hoaian89,项目名称:DAA,代码行数:31,代码来源:StudentSyn.ascx.cs

示例13: DeserializeModulePermissions

        static void DeserializeModulePermissions(XmlNodeList nodeModulePermissions, int portalId, ModuleInfo module)
        {
            var objRoleController = new RoleController();
            var objPermissionController = new PermissionController();

            foreach (XmlNode node in nodeModulePermissions)
            {
                var permissionKey = XmlUtils.GetNodeValue(node, "permissionkey", "");
                var permissionCode = XmlUtils.GetNodeValue(node, "permissioncode", "");
                var roleName = XmlUtils.GetNodeValue(node, "rolename", "");
                var allowAccess = XmlUtils.GetNodeValueBoolean(node, "allowaccess");

                var roleId = int.MinValue;
                switch (roleName)
                {
                    case Globals.glbRoleAllUsersName:
                        roleId = Convert.ToInt32(Globals.glbRoleAllUsers);
                        break;
                    case Globals.glbRoleUnauthUserName:
                        roleId = Convert.ToInt32(Globals.glbRoleUnauthUser);
                        break;
                    default:
                        var objRole = objRoleController.GetRoleByName(portalId, roleName);
                        if (objRole != null)
                        {
                            roleId = objRole.RoleID;
                        }
                        break;
                }
                if (roleId != int.MinValue)
                {
                    var permissionId = Convert.ToInt32(- 1);
                    var arrPermissions = objPermissionController.GetPermissionByCodeAndKey(permissionCode, permissionKey);

                    int i;
                    for (i = 0; i <= arrPermissions.Count - 1; i++)
                    {
                        var permission = (PermissionInfo) (arrPermissions[i]);
                        permissionId = permission.PermissionID;
                    }

                    // if role was found add, otherwise ignore
                    if (permissionId != - 1)
                    {
                        var modulePermission = new ModulePermissionInfo
                                                   {
                                                       ModuleID = module.ModuleID,
                                                       PermissionID = permissionId,
                                                       RoleID = roleId,
                                                       AllowAccess = allowAccess
                                                   };
                        module.ModulePermissions.Add(modulePermission);
                    }
                }
            }
        }
开发者ID:DNNCommunity,项目名称:DNN.FormAndList,代码行数:56,代码来源:ModuleSerializationController.cs

示例14: SexyContentDesignersGroupConfigured

 /// <summary>
 /// Returns true if a DotNetNuke User Group "SexyContent Designers" exists and contains at minumum one user
 /// </summary>
 /// <param name="portalId"></param>
 /// <returns></returns>
 public static bool SexyContentDesignersGroupConfigured(int portalId)
 {
     var roleControl = new RoleController();
     var role = roleControl.GetRoleByName(portalId, SexyContentGroupName);
     return role != null;
 }
开发者ID:BravoSierra,项目名称:2sxc,代码行数:11,代码来源:SexyContent.cs

示例15: UpgradeToVersion621

        private static void UpgradeToVersion621()
        {
            //update administrators' role description.
            var portalController = new PortalController();
            var roleController = new RoleController();
            var moduleController = new ModuleController();
            foreach (PortalInfo portal in portalController.GetPortals())
            {
                var role = roleController.GetRoleByName(portal.PortalID, "Administrators");
                if(role != null && role.Description == "Portal Administrators")
                {
                    role.Description = "Administrators of this Website";
                    roleController.UpdateRole(role);
                }

                role = roleController.GetRoleByName(portal.PortalID, "Subscribers");
                if (role != null && role.Description == "A public role for portal subscriptions")
                {
                    role.Description = "A public role for site subscriptions";
                    roleController.UpdateRole(role);
                }

                //update about me's template
                var myProfileTabId = TabController.GetTabByTabPath(portal.PortalID, "//ActivityFeed//MyProfile", string.Empty);
                if(myProfileTabId != Null.NullInteger)
                {
                    var tabModules = moduleController.GetTabModules(myProfileTabId);
                    foreach(var module in tabModules.Values)
                    {
                        var settings = moduleController.GetTabModuleSettings(module.TabModuleID);
                        if(settings.ContainsKey("ProfileTemplate") && settings["ProfileTemplate"].ToString().Contains("<div class=\"pBio\">"))
                        {
                            var template = @"<div class=""pBio"">
                                    <h3 data-bind=""text: AboutMeText""></h3>
                                    <span data-bind=""text: EmptyAboutMeText, visible: Biography().length==0""></span>
                                    <p data-bind=""html: Biography""></p>
                                    </div>
                                    <div class=""pAddress"">
                                    <h3 data-bind=""text: LocationText""></h3>
                                    <span data-bind=""text: EmptyLocationText, visible: Street().length=0 && Location().length==0 && Country().length==0 && PostalCode().length==0""></span>
                                    <p><span data-bind=""text: Street()""></span><span data-bind=""visible: Street().length > 0""><br/></span>
                                    <span data-bind=""text: Location()""></span><span data-bind=""visible: Location().length > 0""><br/></span>
                                    <span data-bind=""text: Country()""></span><span data-bind=""visible: Country().length > 0""><br/></span>
                                    <span data-bind=""text: PostalCode()""></span>
                                    </p>
                                    </div>
                                    <div class=""pContact"">
                                    <h3 data-bind=""text: GetInTouchText""></h3>
                                    <span data-bind=""text: EmptyGetInTouchText, visible: Telephone().length==0 && Email().length==0 && Website().length==0 && IM().length==0""></span>
                                    <ul>
                                    <li data-bind=""visible: Telephone().length > 0""><strong><span data-bind=""text: TelephoneText"">:</span></strong> <span data-bind=""text: Telephone()""></span></li>
                                    <li data-bind=""visible: Email().length > 0""><strong><span data-bind=""text: EmailText"">:</span></strong> <span data-bind=""text: Email()""></span></li>
                                    <li data-bind=""visible: Website().length > 0""><strong><span data-bind=""text: WebsiteText"">:</span></strong> <span data-bind=""text: Website()""></span></li>
                                    <li data-bind=""visible: IM().length > 0""><strong><span data-bind=""text: IMText"">:</span></strong> <span data-bind=""text: IM()""></span></li>
                                    </ul>
                                    </div>
                                    <div class=""dnnClear""></div>";
                            moduleController.UpdateTabModuleSetting(module.TabModuleID, "ProfileTemplate", template);
                        }
                    }
                }
            }
        }
开发者ID:biganth,项目名称:Curt,代码行数:63,代码来源:Upgrade.cs


注:本文中的DotNetNuke.Security.Roles.RoleController.GetRoleByName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。