private CasbinRule SavePolicyLine(string ptype, IList <string> rule) { var line = new CasbinRule(); line.PType = ptype; if (rule.Count() > 0) { line.V0 = rule[0]; } if (rule.Count() > 1) { line.V1 = rule[1]; } if (rule.Count() > 2) { line.V2 = rule[2]; } if (rule.Count() > 3) { line.V3 = rule[3]; } if (rule.Count() > 4) { line.V4 = rule[4]; } if (rule.Count() > 5) { line.V5 = rule[5]; } return(line); }
private CasbinRule SavePolicyLine(string sec, string ptype, int fieldIndex, params string[] fieldValues) { 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]; } return(line); }
private string GetPolicyContent(CasbinRule rule) { StringBuilder sb = new StringBuilder(rule.PType); void Append(string v) { if (string.IsNullOrEmpty(v)) { return; } sb.Append($", {v}"); } Append(rule.V0); Append(rule.V1); Append(rule.V2); Append(rule.V3); Append(rule.V4); Append(rule.V5); return(sb.ToString()); }
private IQueryable <CasbinRule> ApplyQueryFilter(IQueryable <CasbinRule> query, CasbinRule line) { 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); } return(query); }