예제 #1
0
        public async override Task <Guid> HandleAsync(CreateProcessoCommand request)
        {
            if (request.Responsaveis.Count() != request.Responsaveis.Distinct().Count())
            {
                throw new ProcessoResponsavelDuplicatedException();
            }

            var responsaveis = await _responsavelRepository.GetResponsaveisByIDsAsync(request.Responsaveis);

            var situacao = await _situacaoRepository.FindAsync(request.SituacaoID);

            var newProcesso = Processo.Create(request.NumeroProcessoUnificado,
                                              request.Distribuicao,
                                              request.PastaFisicaCliente,
                                              request.Descricao,
                                              request.SegredoJustica,
                                              situacao,
                                              responsaveis,
                                              request.ProcessoPaiID);

            _processoRepository.Add(newProcesso);
            await _processoRepository.SaveChangesAsync();

            return(newProcesso.ID);
        }
예제 #2
0
        public void GivenProcessos(Table table)
        {
            var processos = table.Rows
                            .Select(p =>
                                    (NumeroProcessoUnificado: new NumeroProcessoUnificadoValueObject(p.GetString("NumeroProcessoUnificado")).Value,
                                     Descricao: p.GetString("Descricao"),
                                     Distribuicao: TryParseDateTime(p.GetString("Distribuicao")),
                                     SegredoJustica: ParseSimNao(p.GetString("SegredoJustica")),
                                     Situacao: p.GetString("Situacao"),
                                     Responsaveis: p.GetString("Responsaveis").Split(',').Select(a => a.Trim()).ToList())
                                    ).ToList();

            var context = ServiceProvider.GetRequiredService <SchmidtContext>();

            var responsaveisNomes = processos.SelectMany(i => i.Responsaveis).ToList();
            var responsaveis      = context.Set <Responsavel>().Where(a => responsaveisNomes.Contains(a.Nome)).ToList();
            var situacoes         = context.Set <Situacao>().Where(a => processos.Select(i => i.Situacao).Contains(a.Nome));

            foreach (var processo in processos)
            {
                var newProcesso = Processo.Create(processo.NumeroProcessoUnificado,
                                                  null,
                                                  null,
                                                  processo.Descricao,
                                                  processo.SegredoJustica,
                                                  situacoes.First(a => a.Nome == processo.Situacao),
                                                  responsaveis,
                                                  null);
                context.Add(newProcesso);
            }
            context.SaveChanges();
        }