First get rid of what ever they are laying their eggs in. Purchase some repellent from an animal supply store and use per instructions.
these tips may help. It's more or indoors but you might find some of the suggestions helpful: https://www.craftylittlegnome.com/flies-house-suddenly/
Heare's a couple home remedies. Also Sentry makes a fly repellant for dogs available at PetSmart and Petco.
Try pouring about a TBS of apple cider vinegar in your pets water dish. One quart. '
Bugs don't like the smell or taste. Then get rid of source of flying bugs