Theory:

Action of magnets
When two magnets are moved close to each other, they either attract or repel each other.
The opposite poles of magnets attract, whereas the similar poles of magnets repel when they are pulled towards each other.
Attraction or repulsion of the magnets depends on the direction of the poles facing each other.
 
magn.png 
Repulsion occurs when like poles (N-N or S-S) of the magnets are kept closer to each other.
Attraction occurs when unlike poles (N-S or S-N) of the magnets are kept closer to each other.
Loss of magnetic property
The magnetic property of a material will be lost if they are
  • heated,
  • hammered,
  • dropped from a certain height, or
  • due to improper storage.
Precautions to retain the magnetic property
The bar magnets should always be kept in pairs separated by a piece of wood keeping the unlike poles on the same side.
 
bar store.jpg
(CBSE Class 6 chapter 13 'Fun with magnets')
  
A piece of iron is kept across the poles for a horseshoe magnet.
 
horseshoeMagnet.png
 
The magnets should be kept away from the electronic gadgets like cassettes, mobiles, television, music system, compact disks (CDs) and the computer. All the electronic gadgets will have magnets in it. When a magnet is placed near these gadgets, it affects magnetic property, and hence spoils the device and the magnet.
Reference:
https://image.shutterstock.com/z/stock-vector-magnetic-attraction-and-repulsion-demonstrated-with-red-and-black-magnet-bars-north-and-south 1705719931.jpg
https://image.shutterstock.com/image-illustration/iron-bars-attached-magnets-600w-155705561.jpg
https://image.shutterstock.com/z/stock-photo-two-magnets-repelling-each-other-isolated-on-a-white-background-north-north-repulsion-science-1112930891.jpg
https://image.shutterstock.com/image-photo/two-magnets-attracting-each-other-600w-1112930897.jpg
https://image.shutterstock.com/z/stock-vector-wireless-connection-technology-electronic-gadgets-and-devices-isometric-icons-collection-with-536516245.jpg