private static void AddEntityTelescope(PlanetHuntersContext context, TelescopeDto telescope)
        {
            Telescope telescopeEntity = new Telescope()
            {
                Name           = telescope.Name,
                Location       = telescope.Location,
                MirrorDiameter = null
            };

            if (telescope.MirrorDiameter != null)
            {
                telescopeEntity.MirrorDiameter = float.Parse(telescope.MirrorDiameter);
            }

            context.Telescopes.Add(telescopeEntity);
        }
示例#2
0
 public static void AddTelescope(TelescopeDto telescopeDto)
 {
     using (var ctx = new PlanetHuntersContext())
     {
         try
         {
             var telescope = new Telescope
             {
                 Name           = telescopeDto.Name,
                 Location       = telescopeDto.Location,
                 MirrorDiameter = telescopeDto.MirrorDiameter ?? 0
             };
             ctx.Telescopes.AddOrUpdate(t => t.Name, telescope);
             ctx.SaveChanges();
             Printer.PrintSuccess(telescope.Name);
         }
         catch (Exception)
         {
             Printer.PrintError();
         }
     }
 }