public bool UpdateEnterpriseRoleToEP(EnterpriseRoleDto enterpriseRole)
 {
     try
     {
         using (var db = new BCEnterpriseContext())
         {
             using (TransactionScope transaction = new TransactionScope())
             {
                 var temp = db.RFARoles.First(x => x.RoleID == enterpriseRole.RoleID && !string.IsNullOrEmpty(x.OwnerID));
                 if (null == temp)
                 {
                     throw new KnownException("该权限中不存在此对象");
                 }
                 if (db.RFARoles.Any(n => n.Name == enterpriseRole.Name && n.RoleID != enterpriseRole.RoleID && (n.OwnerID ?? "") == (enterpriseRole.OwnerID ?? "")))
                 {
                     throw new KnownException("角色名冲突,请更改角色名后重试");
                 }
                 if (null == db.Enterprises.Where(x => x.EnterpriseID.Equals(enterpriseRole.OwnerID)))
                 {
                     throw new KnownException("企业ID不合法");
                 }
                 temp.Name        = enterpriseRole.Name.Trim();
                 temp.Available   = enterpriseRole.Available;
                 temp.Description = enterpriseRole.Description;
                 temp.OwnerID     = enterpriseRole.OwnerID;
                 if (!string.IsNullOrEmpty(enterpriseRole.FunctionIDs))
                 {
                     SetEnterpriseRoleFunction(enterpriseRole.RoleID, enterpriseRole.FunctionIDs);
                 }
                 if (0 <= db.SaveChanges())
                 {
                     transaction.Complete();
                     return(true);
                 }
                 else
                 {
                     return(false);
                 }
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public string AddEnterpriseRoleToEP(EnterpriseRoleDto enterpriseRole)
 {
     using (var db = new BCEnterpriseContext())
     {
         if (db.RFARoles.Any(n => n.Name == enterpriseRole.Name && (n.OwnerID ?? "").Equals(enterpriseRole.OwnerID ?? "") && n.RoleID != enterpriseRole.RoleID))
         {
             throw new KnownException("角色名冲突,请更改角色名后重试");
         }
         var temp = db.Enterprises.FirstOrDefault(x => x.EnterpriseID.Equals(enterpriseRole.OwnerID));
         if (null == temp && !string.IsNullOrEmpty(enterpriseRole.OwnerID))
         {
             throw new KnownException("企业ID不合法");
         }
         if (string.IsNullOrEmpty(enterpriseRole.OwnerID))
         {
             throw new KnownException("没有权限添加公用角色");
         }
         var role = new ML.BC.EnterpriseData.Model.RFARole
         {
             Name        = enterpriseRole.Name,
             OwnerID     = enterpriseRole.OwnerID,
             Description = enterpriseRole.Description,
             Available   = enterpriseRole.Available
         };
         //  事务处理Authorizations表添加成功和RFARole表添加成功需要同时满足。
         using (TransactionScope transaction = new TransactionScope())
         {
             db.RFARoles.Add(role);
             db.SaveChanges();
             var roleId = db.RFARoles.Where(x => x.Name.Equals(enterpriseRole.Name)).Select(n => n.RoleID);
             if (SetEnterpriseRoleFunction(roleId.First(), enterpriseRole.FunctionIDs))
             {
                 transaction.Complete();
                 return(role.Name);
             }
             else
             {
                 throw new KnownException("保存角色功能失败");
             }
         }
     }
 }