public Framework.RbacRole AddOrUpdate(Framework.RbacRole role) { RbacMetaData rbacMetaData = new RbacMetaData(); rbacMetaData.ValidateAndGetRbacXmlDocument(role.MetaDataRbac); if (rbacMetaData.XmlValidationErrors.Count > 0) { RbacException.Raise("Cannot save role meta data, XML validation failed!" + Environment.NewLine + rbacMetaData.XmlValidationErrors.ToLine()); } rbacMetaData.ValidateAndGetEntitlementXmlDocument(role.MetaDataEntitlements); if (rbacMetaData.XmlValidationErrors.Count > 0) { RbacException.Raise("Cannot save role entitlement meta data, XML validation failed!" + Environment.NewLine + rbacMetaData.XmlValidationErrors.ToLine()); } RbacRole dbRole = null; try { using (var ctx = new Entities(ConnectionString)) { dbRole = ctx.RbacRoles.Where(r => r.RoleId == role.RoleId).SingleOrDefault(); if (dbRole == null) //try with name { dbRole = ctx.RbacRoles.Where(r => r.Name.Equals(role.Name, StringComparison.OrdinalIgnoreCase)).SingleOrDefault(); } if (dbRole == null) { RbacRole newRole = Assign(role); newRole.Version = 1; dbRole = ctx.RbacRoles.Add(newRole); } else { dbRole.Name = role.Name; dbRole.Description = role.Description; dbRole.MetaDataRbac = GetEncryptedString(role.MetaDataRbac); dbRole.MetaDataEntitlements = GetEncryptedString(role.MetaDataEntitlements); dbRole.Version = role.Version + 1; } ctx.SaveChanges(); } } catch (DbEntityValidationException e) { RaiseError(e); } catch (DbUpdateException dbe) { RaiseError(dbe); } return(Assign(dbRole)); }
public Framework.RbacRole GetRole(string roleName) { Framework.RbacRole role = null; using (var ctx = new Entities(ConnectionString)) { RbacRole dbRbacRole = ctx.RbacRoles.Where(r => r.Name.Equals(roleName, StringComparison.OrdinalIgnoreCase)).SingleOrDefault(); if (dbRbacRole != null) { role = Assign(dbRbacRole); } } return(role); }
public Framework.RbacRole GetRole(int roleId) { Framework.RbacRole role = null; using (var ctx = new Entities(ConnectionString)) { RbacRole dbRbacRole = ctx.RbacRoles.Where(r => r.RoleId == roleId).SingleOrDefault(); if (dbRbacRole != null) { role = Assign(dbRbacRole); } } return(role); }
private RbacRole Assign(Framework.RbacRole rbacRole) { if (rbacRole == null) { return(null); } RbacRole newRole = new RbacRole(); newRole.RoleId = rbacRole.RoleId; newRole.RbacId = rbacRole.RbacId; newRole.Name = rbacRole.Name; newRole.Description = rbacRole.Description; newRole.MetaDataRbac = GetEncryptedString(rbacRole.MetaDataRbac); newRole.MetaDataEntitlements = GetEncryptedString(rbacRole.MetaDataEntitlements); newRole.Version = rbacRole.Version; return(newRole); }
private Framework.RbacRole Assign(RbacRole rbacRole) { if (rbacRole == null) { return(null); } Framework.RbacRole newRbacRole = new Framework.RbacRole(); newRbacRole.RbacId = rbacRole.RbacId; newRbacRole.RoleId = rbacRole.RoleId; newRbacRole.Name = rbacRole.Name; newRbacRole.Description = rbacRole.Description; if (!HideSensitiveData) { newRbacRole.MetaDataRbac = GetDecryptedString(rbacRole.MetaDataRbac); newRbacRole.MetaDataEntitlements = GetDecryptedString(rbacRole.MetaDataEntitlements); } newRbacRole.Version = (int)rbacRole.Version; return(newRbacRole); }