用户及角色对字段的权限[代码实录]
代码1:
var account = loginContext.User.Account; var roles = loginContext.Roles; List<BuilderTableColumn> zdyList = new List<BuilderTableColumn>(); foreach (var e in columnFields) { if (account == "System") { e.IsEdit = true; zdyList.Add(e); } else if (e.ColumnName.ToLower() == account || e.ColumnName == "Sid" || e.ColumnName == "ContestContent" || e.ColumnName == "Id") { if (e.ColumnName == "Id") { e.IsEdit = false; e.IsReadOnly = true; } else if (e.ColumnName.ToLower() == account) { e.IsEdit = true; } else { e.IsReadOnly = true; e.IsEdit = false; } zdyList.Add(e); } }
代码2:
foreach (var r in roles) { foreach (var e in columnFields) { if (e.ColumnName == "Sid" || e.ColumnName == "ContestContent") { e.IsReadOnly = true; e.IsEdit = false; e.IsList = true; } else if (e.ColumnName.ToLower() == r.Name) { e.IsEdit = true; e.IsList = true; e.IsReadOnly = false; } else { e.IsReadOnly = true; e.IsEdit = false; e.IsList = false; } zdyList.Add(e); } }
代码3:
foreach (var r in roles) { List<string> fields = _revelanceApp.Get(Define.ROLEDATAPROPERTY, r.Id, "VPlayer"); foreach (var e in columnFields) { if (e.ColumnName.ToLower() == r.Name) { e.IsEdit = true; e.IsList = true; e.IsReadOnly = false; } else { string fieldName = e.ColumnName.ToLower(); foreach (var f in fields) { e.IsReadOnly = true; e.IsEdit = false; e.IsList = false; if (fieldName == f.ToLower()) { e.IsReadOnly = true; e.IsEdit = false; e.IsList = true; break; } } } zdyList.Add(e); } }