/// <summary>
 /// 设置菜单是否被选
 /// </summary>
 /// <param name="currentRoles"></param>
 private void SetMenuFunctionIsCheck(Roles currentRoles)
 {
     if (currentRoles.FunctionsInRoles.Any(p => p.FunctionItem.IsLeaf == false && p.FunctionItem.IsButton == false && p.FunctionItem.LevelCode.Length != 2))
     {
         currentRoles.FunctionsInRoles.Where(p => p.FunctionItem.IsLeaf == false && p.FunctionItem.IsButton == false && p.FunctionItem.LevelCode.Length != 2).ToList().ForEach(r =>
         {
             if (r.IsValid)
             {
                 //获取功能项,设置自定义IsChecked为true
                 var fItem = r.FunctionItem;
                 fItem.IsClickStatus = false;
                 bool allChildrenChecked = fItem.SubItems.All(a => a.IsChecked == true);
                 if (allChildrenChecked)
                 {
                     fItem.IsChecked = true;
                 }
                 else
                 {
                     fItem.IsChecked = null;
                 }
             }
             else
             {
                 //获取功能项,设置自定义IsChecked为false
                 var fItem = r.FunctionItem;
                 fItem.IsClickStatus = false;
                 fItem.IsChecked = false;
             }
         });
     }
 }
        /// <summary>
        /// 设置页面是否被选
        /// </summary>
        /// <param name="currentRoles"></param>
        private void SetViewFunctionIsCheck(Roles currentRoles)
        {
            if (currentRoles.FunctionsInRoles.Any(p => p.FunctionItem.IsLeaf == true))
            {
                currentRoles.FunctionsInRoles.Where(p => p.FunctionItem.IsLeaf == true).ToList().ForEach(r =>
                {
                    if (r.IsValid)
                    {
                        //获取功能项,设置自定义IsChecked为true
                        var fItem = r.FunctionItem;
                        fItem.IsClickStatus = false;
                        bool allChildrenChecked = fItem.SubItems.All(x => x.IsChecked == true);

                        if (allChildrenChecked)
                        {
                            fItem.IsChecked = true;
                        }
                        else
                        {
                            fItem.IsChecked = null;
                        }
                    }
                    else
                    {
                        //获取功能项,设置自定义IsChecked为false
                        var fItem = r.FunctionItem;
                        fItem.IsClickStatus = false;
                        fItem.IsChecked = false;

                    }
                });
            }
        }
 /// <summary>
 /// 设置当前角色是否可编辑
 /// </summary>
 private void SetIsRolesEnabled(Roles currentRoles)
 {
     if (currentRoles == null || currentRoles.RoleName != "系统管理员")
     {
         IsRoleEnabled = true;
     }
     else
     {
         IsRoleEnabled = false;
     }
 }
 /// <summary>
 /// 设置应用或者应用下面的页面按钮是否可用
 /// </summary>
 /// <param name="currentRoles"></param>
 private void SetFunctionIsCheck(Roles currentRoles)
 {
     if (currentRoles != null && currentRoles.FunctionsInRoles != null)
     {
         StatusData.roles = currentRoles;
         var roleApplications = currentRoles.FunctionsInRoles;
         if (roleApplications != null)
         {
             SetButtonFunctionIsCheck(currentRoles);
             SetViewFunctionIsCheck(currentRoles);
             SetMenuFunctionIsCheck(currentRoles);
             SetApplicationIsCheck(currentRoles);
         }
         RoleApplications = roleApplications.Select(p => p.FunctionItem).Where(p => p.LevelCode.Length == 2);
     }
     else
     {
         RoleApplications = null;
     }
 }
        /// <summary>
        /// 按钮师傅被选中
        /// </summary>
        /// <param name="currentRoles"></param>
        private void SetButtonFunctionIsCheck(Roles currentRoles)
        {
            if (currentRoles.FunctionsInRoles.Any(p => p.FunctionItem.IsButton == true))
            {
                currentRoles.FunctionsInRoles.Where(p => p.FunctionItem.IsButton == true).ToList().ForEach(r =>
                {
                    if (r.IsValid)
                    {
                        //获取功能项,设置自定义IsChecked为true
                        var fItem = r.FunctionItem;
                        fItem.IsClickStatus = false;
                        fItem.IsChecked = true;

                    }
                    else
                    {
                        //获取功能项,设置自定义IsChecked为false
                        var fItem = r.FunctionItem;
                        fItem.IsClickStatus = false;
                        fItem.IsChecked = false;

                    }
                });
            }
        }
        private void OnAdd(object sender)
        {
            if (SelCurrentApplication == null)
            {
                MessageEventAggregatorRepository.EventAggregator.Publish<MessageEvent>(new MessageEvent { Message = "请先选择应用!", MessageType = MessageType.Info });
                return;
            }
            Roles role = new Roles();
            //role.RoleId = this._service.EntityContainer.GetEntitySet<Roles>().Count == 0 ? 1 :
            //    this._service.EntityContainer.GetEntitySet<Roles>().Max(p => p.RoleId) + 1;
            role.Application = SelCurrentApplication;
            //增加角色的同时需要增加FunctionsInRoles
            SelCurrentApplication.FunctionItems.ToList().ForEach(f =>
                {
                    FunctionsInRoles fr = new FunctionsInRoles();
                    fr.Role = role;
                    fr.FunctionItem = f;
                });

            this.roles.Items.MoveCurrentToLast();
            this._service.EntityContainer.GetEntitySet<Roles>().Add(role);
            RefreshButtonState();
        }
Beispiel #7
0
        // RoleProvider.CreateRole
        public override void CreateRole(string rolename)
        {
            if (rolename.Contains(","))
            {
                throw new ArgumentException("Role names cannot contain commas.");
            }

            if (RoleExists(rolename))
            {
                throw new ProviderException("Role name already exists.");
            }

            using (var db = new SecurityEntities())
            {
                var app = db.Applications.SingleOrDefault(a => a.ApplicationName == ApplicationName);
                var role = new UniCloud.Security.Models.Roles { RoleName = rolename, Application = app };
                db.Roles.Add(role);
                app.FunctionItems.ToList().ForEach(f =>
                    db.FunctionsInRoles.Add(new FunctionsInRoles { Role = role, FunctionItem = f }));
                if (db.SaveChanges() > 0)
                {
                    creatRoleStatus = true;
                }
                else
                {
                    creatRoleStatus = false;
                }
            }
        }