Example #1
0
        public void SetCutomterPermissionObj(string RoleID, List<CustomerPermission> objs, ref string strResult)
        {
            try
            {
                using (EntityMenuCustomPermBLL bll = new EntityMenuCustomPermBLL())
                {
                    if (string.IsNullOrWhiteSpace(RoleID))
                    {
                        return;
                    }

                    RoleEntityMenuBLL roleEmBll = new RoleEntityMenuBLL();
                    roleEmBll.UpdateRoleInfo(RoleID, strResult);//修改信息
                    strResult = string.Empty;
                    IQueryable<T_SYS_ENTITYMENUCUSTOMPERM> cuspers = bll.GetCustomPermByRoleID(RoleID);
                    //if (cuspers != null)
                    //{
                    //    if (cuspers.Count() > 0)
                    //    {
                    //        foreach (T_SYS_ENTITYMENUCUSTOMPERM item in cuspers)
                    //        {
                    //            string strId = item.ENTITYMENUCUSTOMPERMID;
                    //            EntityMenuCustomPermDelete(strId);
                    //        }
                    //    }
                    //}
                    SysPermissionBLL bllPer = new SysPermissionBLL();
                    T_SYS_ROLE entRole = GetSysRoleSingleInfoById(RoleID);//获取角色ID实体对象

                    foreach (var Menus in objs)
                    {
                        if (Menus.PermissionValue == null)
                        {
                            continue;
                        }

                        if (Menus.PermissionValue.Count() == 0)
                        {
                            continue;
                        }
                        T_SYS_ENTITYMENU entMenu = GetSysMenuByID(Menus.EntityMenuId);
                        foreach (var Perms in Menus.PermissionValue)
                        {
                            if (Perms.OrgObjects == null)
                            {
                                continue;
                            }

                            if (Perms.OrgObjects.Count() == 0)
                            {
                                continue;
                            }

                            T_SYS_PERMISSION entPer = bllPer.GetAttachSysPermissionByID(Perms.Permission);//获取权限实体对象
                            foreach (var OrgIns in Perms.OrgObjects)
                            {
                                T_SYS_ENTITYMENUCUSTOMPERM customerPer = new T_SYS_ENTITYMENUCUSTOMPERM();
                                customerPer.ENTITYMENUCUSTOMPERMID = Guid.NewGuid().ToString();

                                customerPer.T_SYS_ROLEReference.EntityKey = entRole.EntityKey;
                                customerPer.T_SYS_ROLE = entRole;
                                //customerPer.T_SYS_ENTITYMENU = entMenu;
                                customerPer.T_SYS_ENTITYMENUReference.EntityKey = entMenu.EntityKey;
                                customerPer.T_SYS_ENTITYMENU = entMenu;
                                //customerPer.T_SYS_PERMISSION = entPer;
                                customerPer.T_SYS_PERMISSIONReference.EntityKey = entPer.EntityKey;
                                customerPer.T_SYS_PERMISSION = entPer;

                                switch (OrgIns.OrgType)
                                {

                                    //公司
                                    case "0":
                                        customerPer.COMPANYID = OrgIns.OrgID;
                                        break;
                                    case "1"://部门
                                        customerPer.DEPARTMENTID = OrgIns.OrgID;
                                        break;
                                    case "2"://岗位
                                        customerPer.POSTID = OrgIns.OrgID;
                                        break;
                                }

                                customerPer.CREATEDATE = DateTime.Now;
                                customerPer.UPDATEDATE = DateTime.Now;

                                EntityMenuCustomPermAdd(customerPer);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                strResult = ex.Message;
            }
        }