Exemple #1
0
        public async Task <Guid> Handle(RegistrarOcorrenciaCommand request, CancellationToken cancellationToken)
        {
            var localFato = _mapper.Map <Endereco>(request.LocalFato);

            var ocorrenciaBuilder = new Ocorrencia.OcorrenciaBuilder((Natureza)request.Natureza, _dateTime.UtcNow)
                                    .DefinirCamposComuns(
                new DelegaciaPolicia(request.DelegaciaPoliciaApuracaoNumero,
                                     (Uf)request.DelegaciaPoliciaApuracaoUf), new Periodo(request.InicioFato, request.FimFato),
                localFato, _dateTime.UtcNow.Year);

            if (!string.IsNullOrWhiteSpace(request.DescricaoFato))
            {
                ocorrenciaBuilder.DefinirDescricaoDosFatos(request.DescricaoFato);
            }

            foreach (var pessoaDto in request.PessoasEnvolvidas)
            {
                var veiculos       = _mapper.Map <List <VeiculoEnvolvido> >(pessoaDto.VeiculosEnvolvidos);
                var objetos        = _mapper.Map <List <ObjetoEnvolvido> >(pessoaDto.ObjetosEnvolvidos);
                var endResidencial = _mapper.Map <Endereco>(pessoaDto.EnderecoResidencial);
                var endComercial   = _mapper.Map <Endereco>(pessoaDto.EnderecoComercial);
                var identidade     =
                    !pessoaDto.IdentidadeRg.HasValue || string.IsNullOrWhiteSpace(pessoaDto.IdentidadeOrgaoEmissor) ||
                    !pessoaDto.IdentidadeUf.HasValue
                        ? null
                        : new Identidade(pessoaDto.IdentidadeRg.Value, pessoaDto.IdentidadeOrgaoEmissor,
                                         (Uf)pessoaDto.IdentidadeUf);
                var nascimento =
                    !pessoaDto.NascimentoData.HasValue || !pessoaDto.NascimentoUf.HasValue
                        ? null
                        : new Nascimento(pessoaDto.NascimentoData.Value, (Uf)pessoaDto.NascimentoUf);
                var estadoCivil   = pessoaDto.EstadoCivil == null ? null : (EstadoCivil?)pessoaDto.EstadoCivil;
                var grauInstrucao = pessoaDto.GrauInstrucao == null ? null : (GrauInstrucao?)pessoaDto.GrauInstrucao;
                var pessoa        = new PessoaEnvolvida((Envolvimento)pessoaDto.Envolvimento, pessoaDto.Nome,
                                                        identidade, pessoaDto.NomeMae, pessoaDto.NomePai, nascimento, pessoaDto.CPF, pessoaDto.Sexo,
                                                        pessoaDto.Passaporte, estadoCivil, grauInstrucao, pessoaDto.NomeSocial, endResidencial,
                                                        endComercial, objetos, veiculos);
                ocorrenciaBuilder.VincularPessoaEnvolvida(pessoa);
            }

            foreach (var meio in request.MeiosEmpregados)
            {
                ocorrenciaBuilder.VincularMeioEmpregado((MeioEmpregado)meio);
            }

            var ocorrencia = ocorrenciaBuilder.Build();

            _uow.OcorrenciaRepository.Insert(ocorrencia);
            await _uow.SaveChangesAsync();

            return(ocorrencia.Id);
        }
Exemple #2
0
 public PessoaEnvolvidaDao(PessoaEnvolvida entity, Guid idOcorrencia) : base(entity)
 {
     id_envolvimento          = (int)entity.Envolvimento;
     nome                     = entity.Nome;
     identidade_rg            = entity.Identidade?.Rg;
     identidade_orgao_emissor = entity.Identidade?.OrgaoEmissor;
     id_identidade_uf         = (int?)entity.Identidade?.Uf;
     nome_mae                 = entity.NomeMae;
     nome_pai                 = entity.NomePai;
     nascimento_data          = entity.Nascimento?.Data;
     id_nascimento_uf         = (int?)entity.Nascimento?.Uf;
     cpf                  = entity.Cpf;
     sexo                 = entity.Sexo;
     passaporte           = entity.Passaporte;
     id_estado_civil      = (int?)entity.EstadoCivil;
     id_grau_instrucao    = (int?)entity.GrauInstrucao;
     nome_social          = entity.NomeSocial;
     endereco_residencial = entity.EnderecoResidencial?.ToString();
     endereco_comercial   = entity.EnderecoComercial?.ToString();
     id_ocorrencia        = idOcorrencia;
 }
 public OcorrenciaBuilder VincularPessoaEnvolvida(PessoaEnvolvida pessoaEnvolvida)
 {
     _ocorrencia._pessoasEnvolvidas.Add(pessoaEnvolvida);
     return(this);
 }