/// <summary> /// 删除一条数据 /// </summary> public int DeleteT(string ID) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; int count = 0; using (MWDatabaseEntities MWDB = new MWDatabaseEntities()) { try { System.Guid gu = new Guid(ID); tblRole objRole = MWDB.tblRole.First(r => r.RoleID == gu); if (objRole != null) { List<tblMenu_Permission_Role> list = MWDB.tblMenu_Permission_Role.Where<tblMenu_Permission_Role>(m => m.RoleID == gu).ToList(); if (list.Count > 0) { foreach (var lists in list) { tblMenu_Permission_Role tblMenu_Permission_RoleObj; tblMenu_Permission_RoleObj = MWDB.tblMenu_Permission_Role.First(m => m.RoleID == lists.RoleID); MWDB.DeleteObject(tblMenu_Permission_RoleObj); count = MWDB.SaveChanges(); if (count>0) { DbLoggerBLL.SysLogger.Info("Delete menu and the role relationship successfully! ID: '" + tblMenu_Permission_RoleObj.ID + "'. User host address: '" + userHostAddress + "'"); } } } } } catch (Exception ex) { DbLoggerBLL.SysLogger.Error("Delete menu and the role relationship failed! ID: '" + ID + "'. User host address: '" + userHostAddress + "' . Exception info" + ex.Message); } } return count; }
/// <summary> /// 逻辑删除 /// </summary> /// <param name="KeyId">需要删除对象的ID</param> /// <returns>返回受影响的行数</returns> public bool Delete(string strKeyId) { //影响行数标记 int counts = 0; //转换成Guid类型 System.Guid KeyIdGuid = new Guid(strKeyId); //需要跟新的对象 tblRole_User tblRole_Users; try { using (MWDatabaseEntities MWDB = new MWDatabaseEntities()) { tblRole_Users = MWDB.tblRole_User.FirstOrDefault(t => t.UserID == KeyIdGuid); if (tblRole_Users != null) { MWDB.DeleteObject(tblRole_Users); counts = MWDB.SaveChanges(); } if (counts > 0) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; DbLoggerBLL.SysLogger.Info("Delete user and role relationship successfully! User and role relationship ID: '" + strKeyId + "'. User host address: '" + userHostAddress + "' . "); return true; } } } catch (Exception ex) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; DbLoggerBLL.SysLogger.Error("Increase user and role relationship failed! User and role relationship ID: '" + strKeyId + "'. User host address: '" + userHostAddress + "' . Exception info:" + ex.Message); return false; } return false; }