/// <summary> /// 创建新的Manager /// </summary> /// <param name="manager">需要创建的Manager,需要在函数外部创建实例, /// 并且为NAME PASSWORD属性赋值,可以选择为MNGR_TYPE属性赋值,但注意这个属性的类型为int,表示对应的TYPE的主键ID</param> /// <returns>true表示成功创建,false表示失败</returns> public static bool AddManager(MANAGER manager) { int count = 0; using (CloudEDUEntities ctx = new CloudEDUEntities()) { try { ctx.MANAGERs.Add(manager); count = ctx.SaveChanges(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.ToString()); return false; } } return count == 1; }
/// <summary> /// 用于更改Manager的Type /// </summary> /// <param name="manager">需要更改的Manager的实例</param> /// <param name="type">需要改为的Type的ID</param> /// <returns>true表示成功创建,false表示失败</returns> public static bool ChangeManagerManagerType(MANAGER manager, int type) { using (CloudEDUEntities ctx = new CloudEDUEntities()) { try { manager.MNGR_TYPE = type; ctx.Entry(manager).State = System.Data.EntityState.Modified; ctx.SaveChanges(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.ToString()); return false; } } return true; //throw new Exception("Not Support Yet"); }
/// <summary> /// 用于更改Manager的一般信息,包括NAME和PASSWORD,不可用于更改PERMISSION和TYPE /// </summary> /// <param name="manager">更改后的Manager实例</param> /// <returns>true表示成功创建,false表示失败</returns> public static bool UpdateManager(MANAGER manager) { using (CloudEDUEntities ctx = new CloudEDUEntities()) { try { ctx.Entry(manager).State = System.Data.EntityState.Modified; ctx.SaveChanges(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.ToString()); return false; } } return true; }
public static bool haveUserPermission(MANAGER manager) { try { PERMISSION[] permission = GetPermissionsByManager(manager); for (int i = 0; i < permission.Length; i++) { if (permission[i].ID == 1) return true; } return false; } catch { return false; } }
/* * 补充getpermissionByManager方法 * 返回将permission[]转化为一个string,用于前台显示 */ public static string getPermissionStringByManager(MANAGER manager) { PERMISSION[] permissions = GetPermissionsByManager(manager); string permissionString=""; for (int i = 0; i < permissions.Length; i++) { permissionString += permissions[i].NAME + ' '; } return permissionString; }
public static PERMISSION[] GetPermissionsByManager(MANAGER manager) { PERMISSION[] permissions = null; using (CloudEDUEntities ctx = new CloudEDUEntities()) { MANAGER mngr = ctx.MANAGERs.Include("PERMISSIONs").Where(m => m.ID == manager.ID).FirstOrDefault(); permissions = mngr.PERMISSIONs.ToArray(); //permissions = ctx.PERMISSIONs.Include("MANAGERs") // .Where(p => p.MANAGERs.Contains(manager)) // .ToArray<PERMISSION>(); } return permissions; }