public bool UpdateRoleRight(string rightkey, string crud, bool value) { bool saved = false; foreach (BORoleRightX roleRight in RoleRights) { if (roleRight.Right.Key.ToUpper().Trim() == rightkey.ToUpper().Trim()) { switch (crud.ToUpper()) { case "CREATE": roleRight.CanCreate = value; break; case "DELETE": roleRight.CanDelete = value; break; case "EXECUTE": roleRight.CanExecute = value; break; case "READ": roleRight.CanRead = value; break; case "UPDATE": roleRight.CanUpdate = value; break; default: return false; } roleRight.Save(); return true; } } if (!saved) { BORoleRightX roleRight = new BORoleRightX(); BORight right = BORight.GetByKey(rightkey); if (right == null) return false; roleRight.Right = right; roleRight.Role = new BORole(this.RoleId); switch (crud.ToUpper()) { case "CREATE": roleRight.CanCreate = value; break; case "DELETE": roleRight.CanDelete = value; break; case "EXECUTE": roleRight.CanExecute = value; break; case "READ": roleRight.CanRead = value; break; case "UPDATE": roleRight.CanUpdate = value; break; default: return false; } roleRight.Save(); RoleRights.Add(roleRight); return true; } return false; }
public BORoleRightXComparer(BORoleRightX.Columns column, BORoleRightX.SortDirections direction) { _column = column; _direction = direction; }
public void MergeRoleRights(BORoleRightXCollection roleRights) { //Save Existing. foreach (BORoleRightX newRoleRight in roleRights) { bool saved = false; foreach (BORoleRightX roleRight in RoleRights) { if (roleRight.Right.ID == newRoleRight.Right.ID && !saved) { roleRight.CanCreate = newRoleRight.CanCreate; roleRight.CanDelete = newRoleRight.CanDelete; roleRight.CanExecute = newRoleRight.CanExecute; roleRight.CanRead = newRoleRight.CanRead; roleRight.CanUpdate = newRoleRight.CanUpdate; roleRight.Save(); saved = true; break; } } if (!saved) { BORoleRightX roleRight = new BORoleRightX(); roleRight.Role = newRoleRight.Role; roleRight.Right = newRoleRight.Right; roleRight.CanCreate = newRoleRight.CanCreate; roleRight.CanDelete = newRoleRight.CanDelete; roleRight.CanExecute = newRoleRight.CanExecute; roleRight.CanRead = newRoleRight.CanRead; roleRight.CanUpdate = newRoleRight.CanUpdate; roleRight.Save(); } } //Remove not existing foreach (BORoleRightX roleRight in RoleRights) { bool exists = false; foreach (BORoleRightX newRoleRight in roleRights) { if (roleRight.Right.ID == newRoleRight.Right.ID) { exists = true; break; } } if (!exists) roleRight.Delete(); } }
public static BORoleRightX GetByRoleAndRight(string roleId, BORight right) { logger.Trace("GetByRoleId"); BORoleRightX a = new BORoleRightX(); SqlConnection con = new SqlConnection(BOBase.GetConnectionString()); con.Open(); try { SqlCommand cmd = new SqlCommand("P_RoleRightX_GetByRoleAndRight", con); cmd.CommandType = CommandType.StoredProcedure; SQLPersistent.SetVarCharParameter(cmd.Parameters, "@RORI_ROLGUID", 50, roleId, false); SQLPersistent.SetInt64Parameter(cmd.Parameters, "@RORI_RITID", right.ID, false); SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleResult); try { if (rdr.Read()) a = new BORoleRightX(rdr); else return null; } catch (Exception ex) { logger.ErrorException("Failed to fetch record", ex); return null; } finally { rdr.Close(); } } finally { con.Close(); } return a; }