Exemple #1
0
        private static void ImportTelescopes()
        {
            using (PlanetHuntersContext context = new PlanetHuntersContext())
            {
                List <TelescopeDto> telescopeDtos = ParseJson <TelescopeDto>(Constants.TelescopesPath);

                foreach (TelescopeDto telescopeDto in telescopeDtos)
                {
                    if (telescopeDto.Name == null || telescopeDto.Name.Length > 255)
                    {
                        Console.WriteLine(Messages.Error);
                        continue;
                    }

                    if (telescopeDto.Location == null || telescopeDto.Location.Length > 255)
                    {
                        Console.WriteLine(Messages.Error);
                        continue;
                    }

                    if (telescopeDto.MirrorDiameter < 0.0001f)
                    {
                        Console.WriteLine(Messages.Error);
                        continue;
                    }

                    Telescope telescopeEntity = new Telescope()
                    {
                        Name           = telescopeDto.Name,
                        Location       = telescopeDto.Location,
                        MirrorDiameter = telescopeDto.MirrorDiameter
                    };

                    HelperMethods.AddTelescopeToDatabase(context, telescopeEntity);
                }
            }
        }