private static List <BsonDocument> GetUserPermissions(string tenantId, string userName, IEnumerable <string> roles) { var dataCenterConnection = DcData.GetConnection(tenantId, TenantDatabase.TenantMongoDb); var client = new MongoClient(dataCenterConnection.ConnectionString); var db = client.GetDatabase(dataCenterConnection.DataBase); var fieldsCollection = db.GetCollection <BsonDocument>(Constants.MongoDbSettings.CollectionNames.FieldPermissions); var filter = new BsonDocument("$or", new BsonArray { new BsonDocument("tenantId", tenantId), new BsonDocument("userName", userName), new BsonDocument("roleName", new BsonDocument("$in", new BsonArray(roles.ToArray()))) }); var result = fieldsCollection.Find(filter).ToListAsync().Result; return(result); }
private static IEnumerable <string> GetUserRoles(string tenantId, string userId) { var dataCenterConnection = DcData.GetConnection(tenantId, TenantDatabase.TenantMongoDb); var client = new MongoClient(dataCenterConnection.ConnectionString); var db = client.GetDatabase(dataCenterConnection.DataBase); var rolesCollection = db.GetCollection <BsonDocument>(Constants.MongoDbSettings.CollectionNames.CustomRoles); var filter = Builders <BsonDocument> .Filter; var project = Builders <BsonDocument> .Projection; if (!String.IsNullOrEmpty(userId)) { var result = rolesCollection .Find(filter.AnyIn(userId, Constants.MongoDbSettings.CollectionNames.UserIdsFieldName)) .Project(project.Include("_id")) .ToListAsync() .Result; return(result.Select(bsrole => bsrole.ToString()).ToList()); } return(new List <string>()); }
private DataCenterConnection GetDataCenterConnection(string tenantId) { var dcc = DcData.GetConnection(tenantId, DbType); return(dcc); }