Exemplo n.º 1
0
        private void DeserializeAstronomers()
        {
            var astronomerDtos = JsonFileOperations.DeserializeJsonCollection <AstronomerDto>(Constants.AstronomerJsonFile);

            using (PlanetHuntersContext ctx = new PlanetHuntersContext())
            {
                AstronomerRepo repo = new AstronomerRepo(ctx);

                foreach (var dto in astronomerDtos)
                {
                    if (dto.FirstName != null && dto.LastName != null)
                    {
                        var a = new Astronomer();
                        Mapper.Map(dto, a);
                        repo.Insert(a);
                        this.DebugLog.AppendLine($"Record {dto.FirstName} {dto.LastName} successfully imported.");
                    }
                    else
                    {
                        this.DebugLog.AppendLine(Constants.InvalidDataFormat);
                    }
                }

                DbUtil.ExecTransaction(ctx);
            }
        }
Exemplo n.º 2
0
        private void DeserializeTelescopes()
        {
            var telescopeDtos = JsonFileOperations.DeserializeJsonCollection <TelescopeDto>(Constants.TelescopeJsonFile);

            using (PlanetHuntersContext ctx = new PlanetHuntersContext())
            {
                TelescopeRepo repo = new TelescopeRepo(ctx);

                foreach (var dto in telescopeDtos)
                {
                    if (dto.Name != null && dto.Location != null)
                    {
                        if (dto.MirrorDiameter != null && dto.MirrorDiameter <= 0)
                        {
                            continue;
                        }

                        var t = new Telescope();
                        Mapper.Map(dto, t);
                        repo.Insert(t);
                        this.DebugLog.AppendLine($"Record {dto.Name} successfully imported.");
                    }
                    else
                    {
                        this.DebugLog.AppendLine(Constants.InvalidDataFormat);
                    }
                }

                DbUtil.ExecTransaction(ctx);
            }
        }