public JsonResult DoInherit(string documentInfoId) { var entity = entities.Set <S_F_DocumentInfo>().FirstOrDefault(i => i.ID == documentInfoId); if (entity != null) { var authList = entities.Set <S_F_DocumentFileAuthority>().Where(i => i.DocumentInfoID == documentInfoId).ToList(); //删除原有继承的权限设置 entities.Set <S_F_DocumentFileAuthority>().Delete(i => i.DocumentInfoID == documentInfoId && i.IsParentAuth == 1); authList.RemoveWhere(a => a.IsParentAuth == 1); //entities.SaveChanges(); //设置继承的权限 entities.Set <S_F_DocumentInfo>().Where(i => i.ID == documentInfoId && i.IsInherit == 0).Update(i => i.IsInherit = 1); var parentAuthList = entities.Set <S_F_DocumentFileAuthority>().Where(i => i.DocumentInfoID == entity.ParentID); foreach (S_F_DocumentFileAuthority authority in parentAuthList) { var auth = authList.FirstOrDefault(a => a.RoleType == authority.RoleType && a.RoleCode == authority.RoleCode); if (auth == null) { auth = new S_F_DocumentFileAuthority(); auth.ID = FormulaHelper.CreateGuid(); auth.DocumentInfoID = entity.ID; auth.AuthType = authority.AuthType; auth.RoleType = authority.RoleType; auth.RoleCode = authority.RoleCode; auth.IsParentAuth = 1; entities.Set <S_F_DocumentFileAuthority>().Add(auth); } else { auth.AuthType = authority.AuthType; auth.IsParentAuth = 1; } } entities.SaveChanges(); //强制权限继承 var forceInherit = ConfigurationManager.AppSettings["ForceInherit"]; if (forceInherit != null && forceInherit.ToLower() == "true") { DocumentCabinetsFO.InheritAuthority(documentInfoId); } } return(Json("")); }