예제 #1
0
        public async Task <ParteEnvolvimento> SalvarParteDoProcesso(PoloViewModel polo, Guid userGuid)
        {
            ParteEnvolvimento envolvimento = MontarObjeto(polo);
            var result = new ParteEnvolvimento();

            try
            {
                if (envolvimento.ParteExiste())
                {
                    await _envolvimentoRepositorio.AtualizarEnvolvido(envolvimento);

                    return(result);
                }
                else
                {
                    result = await _envolvimentoRepositorio.CadastrarEnvolvimento(envolvimento, userGuid);

                    return(result);
                }
            }
            catch (Exception ex)
            {
                //loggar erro
                throw;
            }
        }
예제 #2
0
        public JsonReturn ObterPolo(int poloId)
        {
            var retorno = new JsonReturn();

            var polo = new PoloViewModel();

            try
            {
                retorno.Object = _envolvimentoService.ObterPoloCadastrado(poloId).Result;

                return(retorno);
            }
            catch (DataNotFoundException dEx)
            {
                //loggar erro
                retorno.Object  = dEx;
                retorno.Status  = HttpStatusCode.NoContent;
                retorno.Message = dEx.Message;
                return(retorno);
            }
            catch (Exception ex)
            {
                //loggar erro
                retorno.Object  = ex;
                retorno.Status  = HttpStatusCode.InternalServerError;
                retorno.Message = ex.Message;
                return(retorno);
            }
        }
        public async Task IncluirAsync(PoloViewModel model)
        {
            AddToken();
            var resposta = await _httpClient.PostAsJsonAsync <PoloViewModel>("v1/Polo", model);

            resposta.EnsureSuccessStatusCode();
        }
        public async Task AlterarAsync(Guid Id, PoloViewModel model)
        {
            AddToken();
            var resposta = await _httpClient.PutAsJsonAsync($"v1/Polo/{Id}", model);

            resposta.EnsureSuccessStatusCode();
        }
예제 #5
0
        public async Task Envolvimento_ObterPolo_Deve_Retornar_id_Maior_que_zero(int id)
        {
            if (id <= 0)
            {
                Assert.LessOrEqual(id, 0);
                return;
            }

            PoloViewModel poloResult = new PoloViewModel
            {
                Id             = id,
                Nome           = "",
                IdParte        = 0,
                IdCliente      = 0,
                IdProfissional = 0,
                Cpf            = "",
                Rg             = "",
                Email          = "",
            };

            _envolvimentoService.Setup(x => x.ObterPoloCadastrado(id)).Returns(Task.FromResult(poloResult));

            var polo = await _envolvimentoService.Object.ObterPoloCadastrado(id);

            Assert.Greater(polo.Id, 0);
        }
        public async Task AlterarEnvolvimentoDoCliente(int idProcesso, int envolvimento, bool principal, Guid userGuid)
        {
            var processo = await _processoRepositorio.ObterProcessoComEnvolvidos(idProcesso);

            if (processo.ClienteEnvolvidoNoCaso())
            {
                var idParte = processo.Polos.FirstOrDefault(x => x.Parte.IdCliente == processo.IdCliente).IdParte;
                await AtualizarEnvolvimento(idProcesso, idParte, envolvimento);
                await AtualizarPrincipal(idProcesso, idParte, principal);
            }
            else
            {
                var parte = await _envolvimentoRepositorio.ObterClienteParte(processo.IdCliente);

                var envolvido = new PoloViewModel
                {
                    Envolvimento = (PoloEnum)envolvimento,
                    IdCliente    = processo.IdCliente,
                    Nome         = processo.ClienteNome,
                    Principal    = principal,
                    IdProcesso   = idProcesso
                };

                if (parte != null)
                {
                    envolvido.Id = parte.Id;
                }
                await SalvarParteDoProcesso(envolvido, userGuid);
            }
        }
예제 #7
0
        public async Task <JsonReturn> Polo([FromBody] PoloViewModel polo)
        {
            var retorno = new JsonReturn();

            try
            {
                ViewBag.CasoId = polo.IdProcesso;

                await _envolvimentoService.SalvarParteDoProcesso(polo, new Guid(Helpers.RetrieveUserClaimGuid(HttpContext)));

                return(retorno);
            }
            catch (InvalidDataException e)
            {
                ViewBag.ErrorList = e.ErrorList;
                //loggar erro
                retorno.Status  = HttpStatusCode.InternalServerError;
                retorno.Message = e.GetBaseException().ToString();

                return(retorno);
            }
            catch (Exception e)
            {
                ViewBag.Message = e.Message;
                //loggar erro
                retorno.Status  = HttpStatusCode.InternalServerError;
                retorno.Message = e.GetBaseException().ToString();

                return(retorno);
            }
        }
예제 #8
0
        public async Task IncluirParteDoProcesso(Guid guid, PoloViewModel polo)
        {
            //PODE ALTERAR ESSE METODO
            ParteEnvolvimento envolvimento = _mapper.Map <ParteEnvolvimento>(polo);

            try
            {
                List <Cliente> clientes;
                if (envolvimento.Parte?.IdCliente > 0)
                {
                    //int[] ids = new List<int>() { (int)envolvimento.Parte.IdCliente }.ToArray<int>();
                    clientes = await _clienteService.ListarClientesPorIdEscritorio(guid);

                    Cliente cliente = clientes.FirstOrDefault(x => x.Id == envolvimento.Parte.IdCliente);

                    envolvimento.Parte.Nome  = cliente.Nome;
                    envolvimento.Parte.Cpf   = cliente.CPF_CNJP;
                    envolvimento.Parte.Email = cliente.Email;
                }
                //verificar se ja existe cliente e/ou funcionario cadastrado como parte
                //if (envolvimento.Parte.CriadoNoCadastroExterno())
                //{
                await _envolvimentoRepositorio.CadastrarEnvolvimento(envolvimento, guid);

                //}
            }
            catch (Exception)
            {
                throw new Exception("Erro ao criar cliente como envolvido, contate o suporte.");
            }
        }
        public async Task <ActionResult <PoloViewModel> > Adicionar(PoloViewModel poloViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(CustomResponse(ModelState));
            }

            var caminho         = "/Paginas/Imagem/Polo/";
            var caminhoAmbiente = _env.WebRootPath;
            var gravaImagem     = Imagens.UploadArquivo(poloViewModel.ImagemUpload1, "curso1", caminho, caminhoAmbiente, false);

            if (gravaImagem.Key == 1)
            {
                return(CustomResponse(gravaImagem.Value));
            }
            poloViewModel.CaminhoImagem1 = gravaImagem.Value;
            gravaImagem = Imagens.UploadArquivo(poloViewModel.ImagemUpload2, "curso2", caminho, caminhoAmbiente, false);
            if (gravaImagem.Key == 1)
            {
                return(CustomResponse(gravaImagem.Value));
            }
            poloViewModel.CaminhoImagem2 = gravaImagem.Value;
            gravaImagem = Imagens.UploadArquivo(poloViewModel.ImagemUpload3, "curso3", caminho, caminhoAmbiente, false);
            if (gravaImagem.Key == 1)
            {
                return(CustomResponse(gravaImagem.Value));
            }
            poloViewModel.CaminhoImagem3 = gravaImagem.Value;
            var result = await _poloService.Adicionar(_mapper.Map <Polo>(poloViewModel));

            return(CustomResponse(poloViewModel));
        }
        private ParteEnvolvimento MontarObjeto(PoloViewModel polo)
        {
            var envolvimento = _mapper.Map <ParteEnvolvimento>(polo);

            envolvimento.Parte = _mapper.Map <Domain.Models.Processo.Parte>(polo);
            //envolvimento.Processo = _processoRepositorio.Obter(polo.IdProcesso).Result;

            if ((envolvimento.IdParte != 0 || envolvimento.Parte.Id != 0) && !polo.Atualizando)
            {
                envolvimento.Parte = null;
            }
            else if (envolvimento.Parte.CriadoNoCadastroExterno())
            {
                envolvimento.Parte.Advogados = new List <Advogado> {
                    _mapper.Map <Domain.Models.Processo.Advogado>(polo.Advogado)
                };
                //envolvimento.Parte.Enderecos = new List<EnderecoParte> { _mapper.Map<Domain.Models.Processo.EnderecoParte>(polo.Endereco) };
                envolvimento.Parte.Empregos = new List <Emprego> {
                    _mapper.Map <Domain.Models.Processo.Emprego>(polo.Emprego)
                };

                envolvimento.Parte.ValidarParte();
            }

            return(envolvimento);
        }
        public async Task IncluirParteDoProcesso(Guid guid, PoloViewModel polo)
        {
            _logger.Information("IncluirParteDoProcesso iniciado - Envolvimento->  {@ParteEnvolvimento}");

            ParteEnvolvimento envolvimento = _mapper.Map <ParteEnvolvimento>(polo);

            try
            {
                List <Cliente> clientes;
                if (envolvimento.Parte?.IdCliente > 0)
                {
                    _logger.Information("IncluirParteDoProcesso IF iniciado - Envolvimento->  {@ParteEnvolvimento}", envolvimento);

                    //int[] ids = new List<int>() { (int)envolvimento.Parte.IdCliente }.ToArray<int>();
                    clientes = await _clienteService.ListarClientesPorIdEscritorio(guid);

                    Cliente cliente = clientes.FirstOrDefault(x => x.Id == envolvimento.Parte.IdCliente);

                    _logger.Information("IncluirParteDoProcesso - cliente->  {@Cliente}", cliente);

                    if (cliente.Tipo == Domain.ViewModels.enums.TipoCliente.PessoaFisica)
                    {
                        envolvimento.Parte.Nome  = cliente.Nome;
                        envolvimento.Parte.Cpf   = cliente.CPF_CNJP;
                        envolvimento.Parte.Email = cliente.Email;
                    }
                    else if (cliente.Tipo == Domain.ViewModels.enums.TipoCliente.PessoaJuridica)
                    {
                        envolvimento.Parte.Nome  = cliente.Nome;
                        envolvimento.Parte.Cnpj  = cliente.CPF_CNJP;
                        envolvimento.Parte.Email = cliente.Email;
                    }
                    else
                    {
                        envolvimento.Parte.Nome  = cliente.Nome;
                        envolvimento.Parte.Cnpj  = "";
                        envolvimento.Parte.Email = "";
                    }
                }
                //verificar se ja existe cliente e/ou funcionario cadastrado como parte
                //if (envolvimento.Parte.CriadoNoCadastroExterno())
                //{
                await _envolvimentoRepositorio.CadastrarEnvolvimento(envolvimento, guid);

                //}
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao criar cliente como envolvido.");
            }
        }
예제 #12
0
        public async Task <PoloViewModel> ObterPoloCadastrado(Guid userGuid, int id, int tipo)
        {
            switch (tipo)
            {
            case 1:
                //var i = new List<int>() { id }.ToArray<int>();

                var taskCliente = await _clienteService.ListarClientesPorIdEscritorio(userGuid);

                var po = taskCliente.FirstOrDefault(x => x.Id == id);

                if (po != null)
                {
                    PoloViewModel polos = new PoloViewModel {
                        Cpf = po.CPF_CNJP, Email = po.Email, Nome = po.Nome, Id = po.Id.GetValueOrDefault()
                    };
                    return(polos);
                }
                return(null);

            case 2:
                var taskProfissional = await _profissionalService.ObtemCompletoAsync(userGuid, id);

                if (taskProfissional != null)
                {
                    PoloViewModel polo2 = new PoloViewModel {
                        Cpf = taskProfissional.CPF_CNJP, Email = taskProfissional.Email, Nome = taskProfissional.Nome, Id = taskProfissional.Id.GetValueOrDefault()
                    };
                    return(polo2);
                }
                return(null);

            case 3:
                //ParteEnvolvimento polo3 = await _envolvimentoRepositorio.ObterPolo(id);
                var envolvido = await _processoService.ListarEnvolvidosPorId(userGuid, id);

                if (envolvido != null)
                {
                    PoloViewModel polo3 = new PoloViewModel {    /* Cpf = envolvido.CPF_CNJP, Email = envolvido.Email,*/
                        Nome = envolvido.Nome, Id = envolvido.IdParte
                    };
                    return(polo3);
                }
                return(null);

            default:
                return(null);
            }
        }
        public async Task <PoloViewModel> ObterPoloCadastrado(Guid userGuid, int id, int tipo)
        {
            switch (tipo)
            {
            case 1:

                var taskCliente = await _clienteService.ListarClientesPorIdEscritorio(userGuid);

                var po = taskCliente.FirstOrDefault(x => x.Id == id);

                if (po != null)
                {
                    PoloViewModel polos = new PoloViewModel {
                        Cpf = po.CPF_CNJP, Email = po.Email, Nome = po.Nome, IdCliente = po.Id.GetValueOrDefault()
                    };
                    return(polos);
                }
                throw new DataNotFoundException("Cliente não encontrado");

            case 2:
                var taskProfissional = await _profissionalService.ObtemCompletoAsync(userGuid, id);

                if (taskProfissional != null)
                {
                    PoloViewModel polo2 = new PoloViewModel {
                        Cpf = taskProfissional.CPF_CNJP, Email = taskProfissional.Email, Nome = taskProfissional.Nome, IdProfissional = taskProfissional.Id.GetValueOrDefault()
                    };
                    return(polo2);
                }
                throw new DataNotFoundException("Profissional não encontrado");

            case 3:
                //ParteEnvolvimento polo3 = await _envolvimentoRepositorio.ObterPolo(id);
                var envolvido = await _processoService.ListarEnvolvidosPorId(userGuid, id);

                if (envolvido != null)
                {
                    PoloViewModel polo3 = new PoloViewModel {    /* Cpf = envolvido.CPF_CNJP, Email = envolvido.Email,*/
                        Nome = envolvido.Nome, IdParte = envolvido.IdParte
                    };
                    return(polo3);
                }
                throw new DataNotFoundException("Parte não encontrado");

            default:
                throw new DataNotFoundException("Erro ao buscar envolvido");
            }
        }
        public async Task <ActionResult <PoloViewModel> > Atualizar(Guid id, PoloViewModel poloViewModel)
        {
            if (id != poloViewModel.Id)
            {
                NotificarErro("O id informado não é o mesmo que foi passado na query");
                return(CustomResponse(poloViewModel));
            }

            if (!ModelState.IsValid)
            {
                return(CustomResponse(ModelState));
            }
            var caminho         = "/Paginas/Imagem/Polo/";
            var caminhoAmbiente = _env.WebRootPath;

            if (poloViewModel.ImagemUpload1 != null)
            {
                var gravaImagem = Imagens.UploadArquivo(poloViewModel.ImagemUpload1, "curso1", caminho, caminhoAmbiente, false);
                if (gravaImagem.Key == 1)
                {
                    return(BadRequest(gravaImagem.Value));
                }
                poloViewModel.CaminhoImagem1 = gravaImagem.Value;
            }
            if (poloViewModel.ImagemUpload2 != null)
            {
                var gravaImagem = Imagens.UploadArquivo(poloViewModel.ImagemUpload2, "curso2", caminho, caminhoAmbiente, false);
                if (gravaImagem.Key == 1)
                {
                    return(BadRequest(gravaImagem.Value));
                }
                poloViewModel.CaminhoImagem2 = gravaImagem.Value;
            }
            if (poloViewModel.ImagemUpload3 != null)
            {
                var gravaImagem = Imagens.UploadArquivo(poloViewModel.ImagemUpload3, "curso3", caminho, caminhoAmbiente, false);
                if (gravaImagem.Key == 1)
                {
                    return(BadRequest(gravaImagem.Value));
                }
                poloViewModel.CaminhoImagem3 = gravaImagem.Value;
            }

            await _poloService.Atualizar(_mapper.Map <Polo>(poloViewModel));

            return(CustomResponse(poloViewModel));
        }
예제 #15
0
        public async Task <ActionResult> Incluir(PoloViewModel model, IEnumerable <IFormFile> File1)
        {
            var imagemConta = 1;

            foreach (var file in File1)
            {
                if (file == null && file.Length == 0)
                {
                    ModelState.AddModelError("", $" {"Imagem "} {imagemConta} {" é obrigatória"}");
                }
                else if (file.Length > 2009393)
                {
                    ModelState.AddModelError("", $" {"Imagem do Curso "} {imagemConta} {" maior que 2 Mb"}");
                }
                using (MemoryStream mStream = new MemoryStream())
                {
                    await file.CopyToAsync(mStream);

                    byte[] bytes = mStream.ToArray();
                    if (imagemConta == 1)
                    {
                        model.ImagemUpload1 = bytes;
                    }
                    if (imagemConta == 2)
                    {
                        model.ImagemUpload2 = bytes;
                    }
                    if (imagemConta == 3)
                    {
                        model.ImagemUpload3 = bytes;
                    }
                }
                imagemConta++;
            }

            if (ModelState.IsValid)
            {
                await _api.IncluirAsync(model);

                return(RedirectToAction(nameof(Alterar)));
            }
            return(View(model));
        }
예제 #16
0
        public async Task <ActionResult> Alterar(PoloViewModel model, IEnumerable <IFormFile> File1)
        {
            var imagemConta = 1;

            foreach (var file in File1)
            {
                if (file != null && file.Length > 0)
                {
                    if (file.Length > 2009393)
                    {
                        ModelState.AddModelError("", $" {"Imagem do Curso "} {imagemConta} {" maior que 2 Mb"}");
                    }
                    using (MemoryStream mStream = new MemoryStream())
                    {
                        await file.CopyToAsync(mStream);

                        byte[] bytes = mStream.ToArray();
                        if (file.FileName == "course1.jpg")
                        {
                            model.ImagemUpload1 = bytes;
                        }
                        if (file.FileName == "course2.jpg")
                        {
                            model.ImagemUpload2 = bytes;
                        }
                        if (file.FileName == "course3.jpg")
                        {
                            model.ImagemUpload3 = bytes;
                        }
                    }
                }
                imagemConta++;
            }

            if (ModelState.IsValid)
            {
                await _api.AlterarAsync(model.Id, model);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
예제 #17
0
        public JsonReturn Polo(int casoId, int?poloId, int?tipo)
        {
            var retorno = new JsonReturn();

            var polo = new PoloViewModel();

            if (poloId != null)
            {
                try
                {
                    retorno.Object = _envolvimentoService.ObterPoloCadastrado(new Guid(Helpers.RetrieveUserClaimGuid(HttpContext)), poloId.Value, tipo.GetValueOrDefault()).Result;

                    return(retorno);
                }
                catch (DataNotFoundException dEx)
                {
                    //loggar erro
                    retorno.Object  = dEx;
                    retorno.Status  = HttpStatusCode.NoContent;
                    retorno.Message = dEx.Message;
                    return(retorno);
                }
                catch (Exception ex)
                {
                    //loggar erro
                    retorno.Object  = ex;
                    retorno.Status  = HttpStatusCode.InternalServerError;
                    retorno.Message = ex.Message;
                    return(retorno);

                    throw;
                }
            }

            retorno.Status = HttpStatusCode.NoContent;

            return(retorno);
        }
예제 #18
0
        public async Task <JsonReturn> EditarPolo([FromBody] PoloViewModel polo)
        {
            var retorno = new JsonReturn();

            polo.Atualizando = true;

            try
            {
                await _envolvimentoService.SalvarParteDoProcesso(polo, new Guid(Helpers.RetrieveUserClaimGuid(HttpContext)));
            }
            catch (Exception ex)
            {
                //loggar erro
                retorno.Status  = HttpStatusCode.InternalServerError;
                retorno.Message = "Erro ao atualizar polo";

                return(retorno);
            }

            ViewBag.CasoId  = polo.IdProcesso;
            retorno.Message = "Polo atualizado com sucesso.";

            return(retorno);
        }
예제 #19
0
        public async Task <JsonReturn> Interno([FromBody] DadosInternosViewModel processo)
        {
            userGuid = new Guid(Helpers.RetrieveUserClaimGuid(HttpContext));

            var retorno = new JsonReturn();

            try
            {
                if (processo.IdEscritorio == null || processo.IdEscritorio == 0)
                {
                    processo.IdEscritorio = _sessionService.ObterIdEscritorioUsuario(userGuid);
                }

                int processoId = await _casoService.SalvarDadosInternos(processo, userGuid);

                if (processo.IdCliente > 0 && (processo.ProcessoId == 0 || processo.ProcessoId == int.MinValue))
                {
                    var polo = new PoloViewModel
                    {
                        Envolvimento = PoloEnum.Ativo,
                        IdProcesso   = processoId,
                        IdCliente    = processo.IdCliente,
                        Principal    = true
                    };

                    _logger.Information("Processos Controller IncluirParteDoProcesso - Envolvimento->  {@ParteEnvolvimento}");

                    //inserir envolvimento com o cliente
                    await _envolvimentoService.IncluirParteDoProcesso(userGuid, polo);
                }

                if (processo.Hierarquia != null)
                {
                    processo.Hierarquia.ProcessoId = processoId;
                    await _hierarquiaService.Salvar(processo.Hierarquia, userGuid);
                }

                if (processo.DadosComplementares != null)
                {
                    foreach (var item in processo.DadosComplementares)
                    {
                        item.IdProcesso = processoId;
                    }

                    await _dadosComplementaresService.PersistirDadosComplementares(processo.DadosComplementares);
                }
                processo.ProcessoId = processoId;

                retorno.Object  = processo;
                retorno.Message = "Caso salvo com sucesso!";

                return(retorno);
            }
            catch (InvalidDataException e)
            {
                userGuid = new Guid(Helpers.RetrieveUserClaimGuid(HttpContext));

                _logger.Error(e.GetBaseException(), "ProcessosController - Interno ->  {@DadosInternosViewModel} -> {userGuid}", processo, userGuid);

                retorno.Message = e.ErrorList[0];
                retorno.Object  = e.ErrorList;
                retorno.Status  = HttpStatusCode.InternalServerError;

                return(retorno);
            }
            catch (Exception e)
            {
                userGuid = new Guid(Helpers.RetrieveUserClaimGuid(HttpContext));

                _logger.Error(e.GetBaseException(), "ProcessosController - Interno ->  {@DadosInternosViewModel} -> {userGuid}", processo, userGuid);

                if (processo.ProcessoId > 0)
                {
                    retorno.Message = "Erro ao atualizar processo.";
                }
                else
                {
                    retorno.Message = "Erro ao inserir processo.";
                }

                retorno.Object = e;
                retorno.Status = HttpStatusCode.InternalServerError;

                return(retorno);
            }
        }
예제 #20
0
        public async Task Envolvimento_SalvarParteDoProcesso_Deve_Falhar_Se_Parte_Id_Menor_Que_Zero(PoloViewModel polo)
        {
            var pe = new ParteEnvolvimento
            {
                Parte = new Domain.Models.Processo.Parte
                {
                    Id             = (int)polo.IdParte,
                    IdCliente      = polo.IdCliente,
                    IdProfissional = polo.IdProfissional
                },
                IdParte = (int)polo.IdParte
            };

            Assert.GreaterOrEqual(pe.Parte.Id, 0);
            Assert.GreaterOrEqual(pe.Parte.IdCliente, 0);
            Assert.GreaterOrEqual(pe.Parte.IdProfissional, 0);

            var guid = Guid.NewGuid();

            _envolvimentoService.Setup(x => x.SalvarParteDoProcesso(polo, guid)).Returns(Task.FromResult(pe));
            var result = await _envolvimentoService.Object.SalvarParteDoProcesso(polo, guid);

            Assert.GreaterOrEqual(result.IdParte, 0);
        }