/// <summary>
 /// 创建新的Permission
 /// </summary>
 /// <param name="permission">需要创建的Manager,需要在函数外部创建实例,并且为NAME和TYPE属性赋值</param>
 /// <returns>true表示成功创建,false表示失败</returns>
 public static bool AddPermission(PERMISSION permission)
 {
     int count = 0;
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         try
         {
             ctx.PERMISSIONs.Add(permission);
             count = ctx.SaveChanges();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
             return false;
         }
     }
     return count == 1;
 }
 public static MANAGER[] GetManagersByPermissions(PERMISSION[] perms)
 {
     MANAGER[] managers = null;
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         IQueryable<MANAGER> mgr = ctx.MANAGERs.Include("PERMISSIONs");
         foreach (PERMISSION p in perms)
         {
             mgr = mgr.Where(m => m.PERMISSIONs.Select(pe => pe.ID).Contains(p.ID));
         }
         managers = mgr.ToArray();
     }
     return managers;
 }
 /// <summary>
 /// 用于更改Permission的一般信息,包括NAME和TYPE
 /// </summary>
 /// <param name="permission">更改后的Permission的实例</param>
 /// <returns>true表示成功创建,false表示失败</returns>
 public static bool UpdatePermission(PERMISSION permission)
 {
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         try
         {
             ctx.Entry(permission).State = System.Data.EntityState.Modified;
             ctx.SaveChanges();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
             return false;
         }
     }
     return true;
 }
 public static MANAGER[] GetManagersByPermission(PERMISSION permission)
 {
     MANAGER[] managers = null;
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         PERMISSION perm = ctx.PERMISSIONs.Include("MANAGERs").Where(p => p.ID == permission.ID).FirstOrDefault();
         managers = perm.MANAGERs.ToArray();
         //managers = (from mngr in ctx.MANAGERs
         //            where mngr.PERMISSIONs.Contains<PERMISSION>(permission)
         //            select mngr).ToArray<MANAGER>();
     }
     return managers;
 }