public void RemoveFilteredPolicy(string sec, string ptype, int fieldIndex, params string[] fieldValues) { if (fieldValues == null || !fieldValues.Any()) { return; } var line = new CasbinRule() { PType = ptype }; var len = fieldValues.Count(); if (fieldIndex <= 0 && 0 < fieldIndex + len) { line.V0 = fieldValues[0 - fieldIndex]; } if (fieldIndex <= 1 && 1 < fieldIndex + len) { line.V1 = fieldValues[1 - fieldIndex]; } if (fieldIndex <= 2 && 2 < fieldIndex + len) { line.V2 = fieldValues[2 - fieldIndex]; } if (fieldIndex <= 3 && 3 < fieldIndex + len) { line.V3 = fieldValues[3 - fieldIndex]; } if (fieldIndex <= 4 && 4 < fieldIndex + len) { line.V4 = fieldValues[4 - fieldIndex]; } if (fieldIndex <= 5 && 5 < fieldIndex + len) { line.V5 = fieldValues[5 - fieldIndex]; } var dbRow = _context.CasbinRule.Where(p => p.PType == line.PType) .Where(p => p.V0 == line.V0) .Where(p => p.V1 == line.V1) .Where(p => p.V2 == line.V2) .Where(p => p.V3 == line.V3) .Where(p => p.V4 == line.V4) .Where(p => p.V5 == line.V5) .FirstOrDefault(); if (dbRow != null) { _context.Entry(dbRow).State = EntityState.Deleted; _context.SaveChanges(); } }
public void RemovePolicy(string sec, string pType, IList <string> rule) { var line = savePolicyLine(pType, rule); var dbRow = _context.CasbinRule.Where(p => p.PType == pType) .Where(p => p.V0 == line.V0) .Where(p => p.V1 == line.V1) .Where(p => p.V2 == line.V2) .Where(p => p.V3 == line.V3) .Where(p => p.V4 == line.V4) .Where(p => p.V5 == line.V5) .FirstOrDefault(); _context.Entry(dbRow).State = EntityState.Deleted; _context.SaveChanges(); }
public void RemoveFilteredPolicy(string sec, string ptype, int fieldIndex, params string[] fieldValues) { if (fieldValues == null || !fieldValues.Any()) { return; } var line = new CasbinRule <TKey>() { PType = ptype }; var len = fieldValues.Count(); if (fieldIndex <= 0 && 0 < fieldIndex + len) { line.V0 = fieldValues[0 - fieldIndex]; } if (fieldIndex <= 1 && 1 < fieldIndex + len) { line.V1 = fieldValues[1 - fieldIndex]; } if (fieldIndex <= 2 && 2 < fieldIndex + len) { line.V2 = fieldValues[2 - fieldIndex]; } if (fieldIndex <= 3 && 3 < fieldIndex + len) { line.V3 = fieldValues[3 - fieldIndex]; } if (fieldIndex <= 4 && 4 < fieldIndex + len) { line.V4 = fieldValues[4 - fieldIndex]; } if (fieldIndex <= 5 && 5 < fieldIndex + len) { line.V5 = fieldValues[5 - fieldIndex]; } var query = _context.CasbinRule.Where(p => p.PType == line.PType); if (!string.IsNullOrEmpty(line.V0)) { query = query.Where(p => p.V0 == line.V0); } if (!string.IsNullOrEmpty(line.V1)) { query = query.Where(p => p.V1 == line.V1); } if (!string.IsNullOrEmpty(line.V2)) { query = query.Where(p => p.V2 == line.V2); } if (!string.IsNullOrEmpty(line.V3)) { query = query.Where(p => p.V3 == line.V3); } if (!string.IsNullOrEmpty(line.V4)) { query = query.Where(p => p.V4 == line.V4); } if (!string.IsNullOrEmpty(line.V5)) { query = query.Where(p => p.V5 == line.V5); } foreach (var dbRow in query) { _context.Entry(dbRow).State = EntityState.Deleted; } _context.SaveChanges(); }