//添加角色
 public void ShowRole(Role role)
 {
     if (role == null)
     {
         if (rolelist != null)
         {
             if (rolelist.Count >= 5)
             {
                 MessageManager._instance.ShowMessage("角色已满");
                 return;
             }
             //for (int i = 0; i < rolelist.Count; i++)
             //{
             //    if (CharacterSelectController._instance.nametxt.text == rolelist[i].Name)
             //    {
             //        MessageManager._instance.ShowMessage("角色名重复");
             //        return;
             //    }
             //}
         }
         Role roleAdd = new Role();
         roleAdd.Name       = CharacterSelectController._instance.nametxt.text;
         roleAdd.Level      = 1;
         roleAdd.Exp        = 0;
         roleAdd.Coin       = 20000;
         roleAdd.Diamond    = 1000;
         roleAdd.Energy     = 100;
         roleAdd.Toughen    = 50;
         roleAdd.Profession = CharacterSelectController._instance.profession;
         roleAdd.IsMan      = CharacterSelectController._instance.isman;
         rolecontroller.AddRole(roleAdd);
     }
 }
        private bool CreateRole(string RoleName)
        {
            RoleController oDnnRoleController = new RoleController();

            RoleInfo oRole1 = oDnnRoleController.GetRoleByName(PortalSettings.PortalId, RoleName);

            if (oRole1 == null)
            {
                // Role does not exist yet
                RoleInfo oRole = new RoleInfo();
                {
                    var withBlock = oRole;
                    withBlock.PortalID       = PortalSettings.PortalId;
                    withBlock.RoleName       = RoleName;
                    withBlock.IsPublic       = false;
                    withBlock.AutoAssignment = false;
                    withBlock.RoleGroupID    = Null.NullInteger;
                    withBlock.Description    = "Auto generated Role";
                }
                oDnnRoleController.AddRole(oRole);
                return(true);
            }
            else
            {
                // Role already exists
                return(false);
            }
        }
Beispiel #3
0
        public void TestAddRoleWithLogin()
        {
            string         token      = LoginContext.GetInstance().GenerateNewToken("1");
            UserContextDTO contextDTO = new UserContextDTO();

            contextDTO.UserDTO = new UserDTO();
            contextDTO.UserDTO.Roles.Add(new RoleDTO()
            {
                RoleId = ESportUtils.ADMIN_ROLE
            });
            contextDTO.Token = token;
            LoginContext.GetInstance().SaveContext(contextDTO);
            var mockRoleService = new Mock <IRoleService>();

            mockRoleService.Setup(x => x.AddRole(new RoleRequest {
                RoleId = "Admin", Description = "Administrador"
            }));
            var controller        = new RoleController(mockRoleService.Object);
            var controllerContext = new HttpControllerContext();
            var httpRequest       = new HttpRequestMessage();

            httpRequest.Headers.Add(ControllerHelper.TOKEN_NAME, token);
            controllerContext.Request    = httpRequest;
            controller.ControllerContext = controllerContext;
            IHttpActionResult response = controller.AddRole(roleRequest);
            var contentResult          = response as OkNegotiatedContentResult <ControllerResponse>;

            Assert.IsTrue(contentResult.Content.Success);
        }
Beispiel #4
0
        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();
            }
        }
Beispiel #5
0
        public void AddRoleTest()
        {
            #region arrange (成功新增)

            // httpContext物件設定
            var httpContext = FakeHttpContextManager.CreateHttpContextBase();
            httpContext.Response.StatusCode = 200;

            // 傳入新增的腳色
            RoleVO roleVO = new RoleVO()
            {
                RoleName = "Admin", Description = "最高權限"
            };

            // 回傳新增後的腳色
            string reMessage = string.Empty;

            _roleService.Stub(o => o.AddRole(Arg <RoleVO> .Is.Anything)).Return(reMessage);

            // 設定httpContext
            _target.CurrentHttpContext = httpContext;

            #endregion

            #region act

            var resultData = _target.AddRole(roleVO);

            var result = (RoleVO)(((JsonResult)resultData).Data);

            #endregion

            #region assert

            // 測試回應狀態
            Assert.AreEqual(_target.CurrentHttpContext.Response.StatusCode, 200);

            // 測試回傳結果
            Assert.AreEqual(result.RoleName, "Admin");
            Assert.AreEqual(result.Description, "最高權限");
            Assert.IsTrue(string.IsNullOrEmpty(result.Message));

            #endregion
        }
        private void AssignToGuestRole(CustomerAccount n)
        {
            try
            {
                var roleCtl  = new RoleController();
                var portalId = PortalSettings.Current.PortalId;
                var ui       = UserController.GetUserById(portalId, Convert.ToInt32(n.Bvin));

                var gRole = roleCtl.GetRoleByName(portalId, GUEST_ROLENAME);

                if (gRole == null)
                {
                    gRole = new RoleInfo();

                    gRole.PortalID = portalId;
                    gRole.RoleName = GUEST_ROLENAME;
                    gRole.IsPublic = false;

                    //Null.NullInteger is giving error in Evoq. Needs to be -1
                    gRole.RoleGroupID = -1; //Null.NullInteger; Default value as per DNN EditRole.ascx.cs BindGroups()
                    gRole.Status      = RoleStatus.Approved;

                    //Need Auto assignment (Not Null in DNN Role table)
                    gRole.AutoAssignment = false;

                    //Need Security Mode (Not Null in DNN Role table)
                    gRole.SecurityMode = SecurityMode.SecurityRole;

                    //Need IsSystemRole (Not Null in DNN Role table)
                    gRole.IsSystemRole = false;

                    //Even if this property are Nullable in DNN Role Table , DNN Store Procedure: AddRole() expects them as non nullable.
                    // Set them with default values. Reference DNN: EditRoles.ascx.cs (Line 382: OnUpdateClick())
                    gRole.Description      = string.Empty;
                    gRole.ServiceFee       = 0;   //Required value 0 if BillingFrequency is 'N'
                    gRole.BillingPeriod    = -1;
                    gRole.BillingFrequency = "N"; //Default in EditRole.ascx.cs

                    gRole.TrialPeriod    = -1;
                    gRole.TrialFrequency = "N"; //Default in EditRole.ascx.cs
                    gRole.TrialFee       = 0;

                    gRole.IconFile = string.Empty;
                    gRole.RSVPCode = string.Empty;

                    gRole.RoleID = roleCtl.AddRole(gRole);
                }

                roleCtl.AddUserRole(portalId, ui.UserID, gRole.RoleID, Null.NullDate, Null.NullDate);
            }
            catch (Exception ex)
            {
                LogError(ex);
                EventLog.LogEvent(ex);
            }
        }
Beispiel #7
0
        private void GivenThereIsAUserWithThisRole(string userName, string password, string roleName)
        {
            var reset       = false;
            var isSuperUser = roleName == "Super User";
            var portalId    = PortalId;
            var user        = UserController.GetUserByName(PortalId, userName);

            if (user == null)
            {
                user = new UserInfo
                {
                    PortalID    = PortalId,
                    Username    = userName,
                    IsSuperUser = isSuperUser,
                    Email       = string.Format("{0}@dnn.com", userName),
                    FirstName   = string.Format("{0} FN", userName),
                    LastName    = string.Format("{0} LN", userName),
                    DisplayName = string.Format("{0} DN", userName),
                    Membership  = { Password = password }
                };
                var res = UserController.CreateUser(ref user);
                reset = true;
            }
            else if (user.IsDeleted)
            {
                UserController.RestoreUser(ref user);
                reset = true;
            }
            user.Membership.Password = password;
            if (!isSuperUser)
            {
                var roles = user.Roles.Where(r => r == roleName);
                if (!roles.Any())
                {
                    var roleController = new RoleController();
                    var role           = roleController.GetRoleByName(PortalId, roleName);
                    if (role == null)
                    {
                        role = new RoleInfo {
                            RoleName = roleName, PortalID = PortalId, RoleGroupID = -1
                        };
                        role.RoleID = roleController.AddRole(role);
                    }
                    RoleController.AddUserRole(user, role, PortalSettings.Current, RoleStatus.Approved, DateTime.Now, Null.NullDate, false, false);
                    reset = true;
                }
            }

            User = user;
            if (reset)
            {
                Config.Touch();
            }
        }
Beispiel #8
0
 public void OnAddRolePressed()
 {
     _messageText.text = "";
     if (_newRole.text == "")
     {
         _messageText.text = "Название не может быть пустым";
     }
     else if (RoleController.AddRole(_newRole.text))
     {
         SceneManager.LoadScene("RolesList");
     }
 }
Beispiel #9
0
        public void TestAddRoleWithoutToken()
        {
            var mockRoleService = new Mock <IRoleService>();

            mockRoleService.Setup(x => x.AddRole(new RoleRequest {
                RoleId = "Admin", Description = "Administrador"
            }));
            var controller             = new RoleController(mockRoleService.Object);
            IHttpActionResult response = controller.AddRole(roleRequest);
            var contentResult          = response as OkNegotiatedContentResult <ControllerResponse>;

            Assert.IsNotNull(contentResult.Content.Message);
        }
    public void On_selectedshow_sure_click()
    {
        if (playerSelected == null)
        {
            return;
        }
        //1、检测姓名是否合法
        if (input_selecredShow_name.value.Length < 3)
        {
            MessageManager._instance.ShowMessage("角色信息不符合要求");
            return;
        }
        Role role = null;

        if (roleList != null)
        {
            foreach (Role roleTemp in roleList)
            {
                if ((roleTemp.Isman && playerSelected.name.IndexOf("boy") >= 0) || (!roleTemp.Isman) && playerSelected.name.IndexOf("gril") >= 0)
                {
                    Debug.Log(roleTemp.Isman);
                    role = roleTemp;
                }
            }
        }
        if (role == null)//不存在角色信息
        {
            Debug.Log("创建角色。。。。。");
            Role newrole = new Role();
            newrole.Name    = input_selecredShow_name.value;
            newrole.Isman   = playerSelected.name.IndexOf("boy") >= 0 ? true : false;
            newrole.Level   = 1;
            newrole.Coin    = 0;
            newrole.Diamond = 0;
            newrole.Exp     = 0;
            newrole.Energy  = 100;
            newrole.Toughen = 50;
            //申请创建角色
            //roleList.Add(newrole);
            roleControll.AddRole(newrole);
            HideSelectRolePanel();
            ShowRolePanel();
            RoleShow(newrole);/////////////////传错参数出现错误。
        }
        else
        {
            HideSelectRolePanel();
            ShowRolePanel();
            RoleShow(role);
        }
    }
    public void AddNewPlayer()  //初始化新角色
    {
        Role roleAdd = new Role();

        roleAdd.Name    = nameInput.value;
        roleAdd.Level   = 1;
        roleAdd.IsMan   = isMan;
        roleAdd.Exp     = 0;
        roleAdd.Coin    = 1000;
        roleAdd.Diamond = 1000;
        roleAdd.Energy  = 100;
        roleAdd.Toughen = 50;
        roleController.AddRole(roleAdd);
    }
        public void AddRole_Success()
        {
            //Act
            var roleViewModel = new RoleViewModel {
                RoleID = 1, Name = "Role3", Description = "Role3 Desc"
            };
            var result        = controller.AddRole(roleViewModel);
            var jsonResponse  = result as JsonResult;
            var data          = result.Data;
            var modelResponse = data as Response <RoleViewModel>;
            var rowAffected   = modelResponse.RowAffected;

            //Assert
            Assert.IsTrue(rowAffected > 0);
        }
Beispiel #13
0
    /// <summary>
    /// Here we create the roles written in the xml file
    /// </summary>
    protected void CreateRoles()
    {
        try
        {
            PortalSettings portalSettings = new PortalSettings();
            int            portalId       = portalSettings.PortalId;
            RoleController rc             = new RoleController();

            System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(Server.MapPath("DesktopModules/AIS/Installer/Modules.xml") /*"C:\\inetpub\\wwwroot\\DNN\\DesktopModules\\AIS\\ListeInterventions\\Roles.xml"*/);
            while (reader.Read())
            {
                reader.MoveToContent();
                if (reader.Name == "role")
                {
                    RoleInfo ri = new RoleInfo();
                    ri.PortalID       = portalId;
                    ri.AutoAssignment = false;
                    ri.Status         = RoleStatus.Approved;
                    if (reader.HasAttributes)
                    {
                        if (reader.GetAttribute("name") != "")
                        {
                            ri.RoleName = reader.GetAttribute("name");
                        }
                        if (reader.GetAttribute("groupID") != "")
                        {
                            ri.RoleGroupID = int.Parse(reader.GetAttribute("groupID"));
                        }
                        if (reader.GetAttribute("public") != "")
                        {
                            ri.IsPublic = bool.Parse(reader.GetAttribute("public"));
                        }
                    }
                    //Don't add existing roles
                    if (!RoleExists(ri))
                    {
                        rc.AddRole(ri);
                    }
                }
            }
        }
        catch (Exception exc)
        {
            //superlabel.Text += "An error occured, please see the event log or contact an administrator for more informations";
        }
    }
    //角色创建确认按钮
    public void OnRoleBuildPancelConfirmClick()
    {
        rolebuildChildDotweenAnimation.DOPlayBackwards();  //隐藏创建角色的面板
        //roleSelectChildDotweenAnimation.DOPlayForward();   //
        //characterNameText.text = characterNameInputLogin.text;

        //判断角色的名字是否符合要求?
        if (characterNameInputLogin.text.Length < 3)
        {
            MessageManger._instance.ShowMessage("角色的名字不能少于3个字符");
            return;
        }

        //判断当前的角色是否已经创建
        Role role = null;

        foreach (var roleTemp in rolelist)
        {
            if ((roleTemp.IsMan && characterSelected.name.IndexOf("boy") >= 0) || (roleTemp.IsMan == false && characterSelected.name.IndexOf("girl") >= 0))
            {
                characterNameInputLogin.text = roleTemp.Name;
                role = roleTemp;
            }
        }
        if (role == null)
        {
            Role roleAdd = new Role();
            roleAdd.IsMan   = characterSelected.name.IndexOf("boy") >= 0 ? true : false;
            roleAdd.Name    = characterNameInputLogin.text;
            roleAdd.Level   = 1;
            roleAdd.Exp     = 0;
            roleAdd.Coin    = 20000;
            roleAdd.Diamond = 1000;
            roleAdd.Energy  = 100;
            roleAdd.Toughen = 50;
            roleController.AddRole(roleAdd);
        }
        else
        {
            ShowRole(role);
        }
    }
Beispiel #15
0
    public void OnCharactershowButtonSureClick()
    {
        //判断角色的名字是否符合规则
        if (characternameInput.value.Length < 3)
        {
            MessageManager._instance.ShowMessage("角色的名字不能少于3个字符");
            return;
        }

        //判断当前的角色是否已经创建
        Role role = null;

        foreach (var roleTemp in roleList)
        {
            if ((roleTemp.IsMan && characterSelected.name.IndexOf("boy") >= 0) || (roleTemp.IsMan == false && characterSelected.name.IndexOf("girl") >= 0))
            {
                characternameInput.value = roleTemp.Name;
                role = roleTemp;
            }
        }

        if (role == null)
        {
            Role roleAdd = new Role();
            roleAdd.IsMan   = characterSelected.name.IndexOf("boy") >= 0 ? true : false;
            roleAdd.Name    = characternameInput.value;
            roleAdd.Level   = 1;
            roleAdd.Exp     = 0;
            roleAdd.Coin    = 20000;
            roleAdd.Diamond = 1000;
            roleAdd.Energy  = 100;
            roleAdd.Toughen = 50;
            roleController.AddRole(roleAdd);
        }
        else
        {
            ShowRole(role);
        }

        OnCharactershowButtonBackClick();
    }
            public void AddUserRole(int portalId, int userId, string roleName)
            {
                var ctl  = new RoleController();
                var role = ctl.GetRoleByName(portalId, roleName);

                if (role == null)
                {
                    role = new RoleInfo
                    {
                        PortalID    = portalId,
                        RoleGroupID = Null.NullInteger,
                        RoleName    = roleName
                    };
                    role.RoleID = ctl.AddRole(role);
                }

                if (ctl.GetUserRole(portalId, userId, role.RoleID) == null)
                {
                    ctl.AddUserRole(portalId, userId, role.RoleID, Null.NullDate, Null.NullDate);
                }
            }
 protected void btnAdd_Click(object sender, EventArgs e)
 {
     try
     {
         RoleInfo role = new RoleInfo();
         role.RoleName        = txtRoleName.Text;
         role.RoleDescription = txtRoleDescription.Text;
         role.Address         = txtAddress.Text;
         role.Phone           = txtPhone.Text;
         role.Fax             = txtFax.Text;
         role.Email           = txtEmail.Text;
         role.UserManager     = ConvertUtility.ToInt32(dropUserManager.SelectedValue);
         role.RoleParentID    = ConvertUtility.ToInt32(dropRoleParentID.SelectedValue);
         RoleController.AddRole(role);
         lblUpdate.Text = MiscUtility.MSG_UPDATE_SUCCESS;
     }
     catch (Exception ex)
     {
         Response.Write(ex.Message);
     }
     btnCancel_Click(null, null);
 }
        protected override void ProcessRecord()
        {
            WriteVerbose("Starting Add Roles Script");

            int RoleGroupID = RoleController.GetOrCreateRoleGroupIdByName(Context, PortalId, RoleGroupName);
            var loopTo      = NrRoles;

            for (int i = 1; i <= loopTo; i++)
            {
                string roleName = Common.Random.GetRandomRoleName();
                int    RoleID   = RoleController.GetRoleIdByName(Context, PortalId, roleName);
                if (RoleID == -1)
                {
                    RoleID = RoleController.AddRole(Context, PortalId, RoleGroupID, roleName);
                    WriteVerbose(string.Format("Created role {0}", roleName));
                }
                else
                {
                    WriteVerbose(string.Format("Role {0} exists already", roleName));
                }
            }
        }
Beispiel #19
0
        protected override void ProcessRecord()
        {
            if (string.IsNullOrEmpty(Rolename))
            {
                Rolename = Common.Random.GetRandomRoleName();
            }
            WriteVerbose(string.Format("Creating Role {0}", Rolename));

            int RoleID      = RoleController.GetRoleIdByName(Context, PortalId, Rolename);
            int RoleGroupID = RoleController.GetOrCreateRoleGroupIdByName(Context, PortalId, RoleGroupName);

            if (RoleID == -1)
            {
                RoleID = RoleController.AddRole(Context, PortalId, RoleGroupID, Rolename);
                WriteVerbose(string.Format("Created role {0}", Rolename));
            }
            else
            {
                WriteVerbose(string.Format("Role {0} exists already", Rolename));
            }

            WriteObject(RoleID);
        }
Beispiel #20
0
        public void TestMethod1()
        {
            //角色管理
            //新增
            RoleSearchDTO adddto       = new RoleSearchDTO();
            var           searchdtostr = TransformHelper.ConvertDTOTOBase64JsonString(adddto);

            testcontroller.GetRoleList(searchdtostr);
            RoleOperateDTO adddtotest = new RoleOperateDTO();

            adddtotest.RoleName = "单元测试角色";
            var addresult   = JsonConvert.DeserializeObject <ResultDTO <object> >(testcontroller.AddRole(adddtotest).Content.ReadAsStringAsync().Result);
            var resultlist1 = JsonConvert.DeserializeObject <List <RoleResultDTO> >(testcontroller.GetRoleList(searchdtostr).Content.ReadAsStringAsync().Result);
            var target      = resultlist1.Where(m => m.RoleName == "单元测试角色").FirstOrDefault();

            Assert.IsNotNull(target);

            //修改
            adddtotest.RoleID   = target.RoleID;
            adddtotest.RoleName = "修改成功的单元测试角色";
            var updateresult = JsonConvert.DeserializeObject <ResultDTO <object> >(testcontroller.UpdateRole(adddtotest).Content.ReadAsStringAsync().Result);
            var resultlist2  = JsonConvert.DeserializeObject <List <RoleResultDTO> >(testcontroller.GetRoleList(searchdtostr).Content.ReadAsStringAsync().Result);

            target = resultlist2.Where(m => m.RoleName == "修改成功的单元测试角色").FirstOrDefault();
            Assert.IsNotNull(target);

            //删除
            RoleSearchDTO deleteDto = new RoleSearchDTO();

            deleteDto.RoleID = target.RoleID;
            var deleteDtoster = TransformHelper.ConvertDTOTOBase64JsonString(deleteDto);
            var deleteresult  = JsonConvert.DeserializeObject <ResultDTO <object> >(testcontroller.DeleteRole(deleteDtoster).Content.ReadAsStringAsync().Result);
            var resultlist3   = JsonConvert.DeserializeObject <List <RoleResultDTO> >(testcontroller.GetRoleList(searchdtostr).Content.ReadAsStringAsync().Result);

            target = resultlist3.Where(m => m.RoleID == target.RoleID).FirstOrDefault();
            Assert.IsNull(target);
        }
Beispiel #21
0
        public async Task AddRole()
        {
            var roleDto = new RoleDto
            {
                Description = "Super Role",
                Name        = "Super Super"
            };

            var addRoleDto = new AddRoleDto()
            {
                Role          = roleDto,
                PermissionIds = new List <int> {
                    1
                }
            };

            var controllerResult = await _controller.AddRole(addRoleDto);

            var response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Assert.Equal(roleDto.Description, response.Description);
            Assert.Equal(roleDto.Name, response.Name);
            Assert.NotEqual(roleDto.Id, response.Id);
        }
Beispiel #22
0
        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)
            {
                lblInvalidGroupName.Visible = true;
                return;
            }


            var modRoles = new List <RoleInfo>();
            var modUsers = new List <UserInfo>();

            foreach (ModulePermissionInfo modulePermissionInfo in ModulePermissionController.GetModulePermissions(ModuleId, TabId))
            {
                if (modulePermissionInfo.PermissionKey == "MODGROUP" && modulePermissionInfo.AllowAccess)
                {
                    if (modulePermissionInfo.RoleID > int.Parse(Globals.glbRoleNothing))
                    {
                        modRoles.Add(roleController.GetRole(modulePermissionInfo.RoleID, PortalId));
                    }
                    else if (modulePermissionInfo.UserID > Null.NullInteger)
                    {
                        modUsers.Add(UserController.GetUserById(PortalId, modulePermissionInfo.UserID));
                    }
                }
            }

            var 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);

            var groupUrl = Globals.NavigateURL(GroupViewTabId, "", new String[] { "groupid=" + roleInfo.RoleID.ToString() });

            if (groupUrl.StartsWith("http://") || groupUrl.StartsWith("https://"))
            {
                const int startIndex = 8;                 // length of https://
                groupUrl = groupUrl.Substring(groupUrl.IndexOf("/", startIndex, StringComparison.InvariantCultureIgnoreCase));
            }
            roleInfo.Settings.Add("URL", groupUrl);

            roleInfo.Settings.Add("GroupCreatorName", UserInfo.DisplayName);
            roleInfo.Settings.Add("ReviewMembers", chkMemberApproved.Checked.ToString());

            TestableRoleController.Instance.UpdateRoleSettings(roleInfo, true);
            if (inpFile.PostedFile != null && 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);
                }
            }

            var notifications = new 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, modUsers);
            }
            else
            {
                //Send notification to Group Moderators informing of new group.
                notifications.AddGroupNotification(Constants.GroupCreatedNotification, GroupViewTabId, ModuleId, roleInfo, UserInfo, modRoles, modUsers);

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

            Response.Redirect(Globals.NavigateURL(GroupViewTabId, "", new String[] { "groupid=" + roleInfo.RoleID.ToString() }));
        }
        /// <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
        /// </history>
        protected void cmdUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                if (Page.IsValid)
                {
                    float  sglServiceFee       = 0;
                    int    intBillingPeriod    = 1;
                    string strBillingFrequency = "N";

                    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;
                    int    intTrialPeriod    = 1;
                    string 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;
                    }

                    RoleController objRoleController = new RoleController();
                    RoleInfo       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;

                    EventLogController objEventLog = new EventLogController();
                    if (RoleID == -1)
                    {
                        if (objRoleController.GetRoleByName(PortalId, objRoleInfo.RoleName) == null)
                        {
                            objRoleController.AddRole(objRoleInfo);
                            objEventLog.AddLog(objRoleInfo, PortalSettings, UserId, "", EventLogController.EventLogType.ROLE_CREATED);
                        }
                        else
                        {
                            UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("DuplicateRole", this.LocalResourceFile), ModuleMessageType.RedError);
                            return;
                        }
                    }
                    else
                    {
                        objRoleController.UpdateRole(objRoleInfo);
                        objEventLog.AddLog(objRoleInfo, PortalSettings, UserId, "", EventLogController.EventLogType.ROLE_UPDATED);
                    }

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

                    Response.Redirect(Globals.NavigateURL());
                }
            }
            catch (Exception exc)  //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
        private static string UpdateRoles(UserInfo objCurrentUser,
                                          PortalSettings objPortalSettings,
                                          UserInfo objUser,
                                          DataRow dr,
                                          string rblImportRoles,
                                          string LocalResourceFile
                                          )
        {
            RoleController objRoleController = new RoleController();
            bool           ByID           = false;
            bool           AutoCreateRole = false;
            string         Roles          = "";

            switch (rblImportRoles)
            {
            case "0":
                return("");

            case "1":
                ByID  = true;
                Roles = (string)dr["RoleIDs"];
                break;

            case "3":
                Roles          = (string)dr["Roles"];
                AutoCreateRole = true;
                break;

            case "2":
                Roles = (string)dr["Roles"];
                break;
            }

            string AdministratorRoleName = "";

            try
            {
                AdministratorRoleName =
                    (objPortalSettings.AdministratorRoleName == DotNetNuke.Common.Utilities.Null.NullString) ? "" : objPortalSettings.AdministratorRoleName;
            }
            catch (Exception Exc)
            {
                Exceptions.LogException(Exc);
            }
            if (AdministratorRoleName == "")
            {
                //for child portals its empty and we need RoleName only to check security, so can use any uniq string - always will be false
                AdministratorRoleName = System.Guid.NewGuid().ToString();
            }

            StringBuilder sb = new StringBuilder();

            foreach (string Role in Roles.Split(new char[] { ',' }))
            {
                if (Role.Trim() == "")
                {
                    continue;
                }

                RoleInfo objRole = null;
                if (ByID)
                {
                    int RoleID = -1;
                    if (Int32.TryParse(Role, out RoleID))
                    {
                        objRole = objRoleController.GetRole(RoleID, objPortalSettings.PortalId);
                    }
                }
                else
                {
                    objRole = objRoleController.GetRoleByName(objPortalSettings.PortalId, Role);
                    if ((objRole == null) && (AutoCreateRole))
                    {
                        objRole                = new RoleInfo();
                        objRole.RoleGroupID    = -1;
                        objRole.RoleName       = Role;
                        objRole.PortalID       = objPortalSettings.PortalId;
                        objRole.AutoAssignment = false;
                        objRole.IsPublic       = false;
                        objRole.TrialPeriod    = -1;
                        objRole.BillingPeriod  = -1;
                        objRole.Status         = RoleStatus.Approved;
                        objRole.RoleID         = objRoleController.AddRole(objRole);
                    }
                }

                //check current user has permissions to import user with specific role
                if (!
                    (objCurrentUser.IsInRole(objRole.RoleName) ||
                     objCurrentUser.IsInRole(AdministratorRoleName) ||
                     objCurrentUser.IsSuperUser
                    ))
                {
                    sb.AppendFormat(Localization.GetString("UserDeniedToImportRole", LocalResourceFile), objCurrentUser.Username,
                                    (ByID ? string.Format("RoleID={0}", objRole.RoleID) : string.Format("RoleName={0}", objRole.RoleName))
                                    );
                    continue;
                }

                if (objRole != null)
                {
                    objRoleController.AddUserRole(objPortalSettings.PortalId, objUser.UserID, objRole.RoleID, DotNetNuke.Common.Utilities.Null.NullDate);
                }
                else
                {
                    sb.AppendFormat(
                        ByID ? Localization.GetString("RoleIDNotFound", LocalResourceFile) : Localization.GetString("RoleNameNotFound", LocalResourceFile),
                        Role);
                }
            }
            return(sb.ToString());
        }