Sometimes it helps to break it down to task and responsibilities, and class or functions should focus on one thing and do that thing well.
You are
1) Checking if BlockTableRecord exists
2) Creating a BlockTableRecord if it does not
3) Inserting a BlockReference from BlockTableRecord
You can break this down to make it more reusable, easier to read, debug, etc.. and many different ways to approach it
To start off with first round of a simple refactor and this will NOT make it robust, re-usable, or close to deployable to many users but start breaking down in different parts and start in better direction.
Ask yourself
Should a function to insert a BlockReference need to worry about creating a BlockTableRecord?
Should it need to care if it was just created or been there for days, years, etc...
One hint would be the function name and to be more correct would be CheckBlockNameCreateIfNotInDrawingInsert. So maybe first step would be getting functions name to contain only one verb.
Its up to you to decide which responsibilities and contracts to implement like
1)Should the function to insert be responsible for checking if it exists and if not exist then call function to create it.
or
2)The Insertion function should Insert.
Can you see how first options now requires insertion function responsible for still creating BlockTableRecords and if you need more than one then it needs to know how to do that.
The insertion function signature could have a parameter for the ObjectId of the BlockTableRecord, which for a BlockTableRecord to have a ObjectId it must be in the drawing(up to you for checking if it is valid, is from correct database, etc...)
Depending on requirements there are many different approaches.
So just making up a quick example and better ways to do it but to get started in better direction
For a short easy example say you have folders containing drawings for blocks and folder is in SearchPaths
3 Functions
InsertBlockReference(Name)
If not In drawing
CreateBlock(Name)
InsertBlock(Id)
CreateBlock(name)
FindFile(Name)
InsertBlock("Path from Filename")
InsertBlock(Id)
......
......
As far as inserting blocks and you are going to get user input and provide visual feedback then I would script insert command.
Unless you want to deal with scaling, scales uniformly, is it annotative, alignment parameters, attributes, attributes with fields, Ucs, etc...
Again just quick example to help maybe push in right direction