private static void AddCountryToDB(MountainDTO mountainDTO)
        {
            var context = new MountainsContext();

            if (mountainDTO.MountainName == null)
            {
                throw new Exception("Mountain name is required");
            }
            var m = new Mountain()
            {
                Name = mountainDTO.MountainName
            };

            foreach (var peakDTO in mountainDTO.Peaks)
            {
                if (peakDTO.PeakName == null)
                {
                    throw new Exception("Peak name is required");
                }
                if (peakDTO.Elevation == null)
                {
                    throw new Exception("Peak elevation is required");
                }
                Peak peak = new Peak();
                peak.Name      = peakDTO.PeakName;
                peak.Elevation = peakDTO.Elevation.GetValueOrDefault();
                m.Peaks.Add(peak);
            }
            foreach (var countryName in mountainDTO.Countries)
            {
                var country = context.Countries.FirstOrDefault(c => c.Name == countryName);
                if (country == null)
                {
                    country = new Country()
                    {
                        Code = countryName.ToUpper().Substring(0, 2),
                        Name = countryName
                    };
                }
                m.Countries.Add(country);
            }
            context.Mountains.Add(m);
            context.SaveChanges();
        }
 private static void AddCountryToDb(MountainsContext context, MountainDTO mountainDTO)
 {
     if(mountainDTO.MountainName == null)
     {
         throw new Exception("Mountain name is required");
     }
     var m = new Mountain() { Name = mountainDTO.MountainName };
     foreach (var peak in mountainDTO.Peaks)
     {
         if(peak.PeakName == null)
         {
             throw new Exception("Peak name is required");
         }
         if(peak.Elevation == null)
         {
             throw new Exception("Peak elevation is required");
         }
         var peakToDb = new Peak()
         {
             Name = peak.PeakName,
             Elevation = peak.Elevation.GetValueOrDefault()
         };
         m.Peaks.Add(peakToDb);
     }
     foreach (var countryName in mountainDTO.Countries)
     {
         var country = context.Countries.FirstOrDefault(c => c.Name == countryName);
         if (country == null)
         {
             country = new Country()
             {
                 Code = countryName.ToUpper().Substring(0, 2),
                 Name = countryName
             };
         }
         country.Mountains.Add(m);
         context.Countries.Add(country);
     }
     context.Mountains.Add(m);
 }