Exemplo n.º 1
0
        public static Funcionario ToDomainModel(FuncionarioCommand funcionarioCommand)
        {
            var funcionario = new Funcionario(
                funcionarioCommand.Nome,
                funcionarioCommand.CPF,
                funcionarioCommand.Celular,
                funcionarioCommand.IdPessoa,
                funcionarioCommand.Funcao,
                funcionarioCommand.EstabelecimentoId,
                funcionarioCommand.Imagem);

            if (!string.IsNullOrEmpty(funcionarioCommand.Email))
            {
                funcionario.DefinirEmail(funcionarioCommand.Email);
            }

            funcionario.AdicionarEndereco(EnderecoAdapter.ToDomainModel(funcionarioCommand.Endereco));

            if (funcionarioCommand.EstabelecimentoId != null)
            {
                funcionario.DefinirEstabelecimento(funcionarioCommand.EstabelecimentoId);
            }
            //if(funcionarioCommand.UsuarioId != null) funcionario.DefinirUsuario(funcionarioCommand.UsuarioId);

            return(funcionario);
        }
Exemplo n.º 2
0
        public static FuncionarioCommand ToModelDomain(Funcionario funcionario)
        {
            if (funcionario == null)
            {
                return(null);
            }

            var funcionarioCommand = new FuncionarioCommand(
                funcionario.Nome,
                funcionario.CPF.Codigo,
                funcionario.Celular.Numero,
                funcionario.Email.Endereco,
                funcionario.Funcao,
                funcionario.EstabelecimentoId,
                ImageHelper.ConverterParaBase64String(funcionario.Imagem));

            funcionarioCommand.IdPessoa  = funcionario.IdPessoa;
            funcionarioCommand.EstaAtivo = funcionario.EstaAtivo;

            if (funcionario.ListaDeEnderecos != null)
            {
                funcionarioCommand.Endereco = EnderecoAdapter.ToModelDomain(funcionario.ListaDeEnderecos.FirstOrDefault());
            }

            funcionarioCommand.Estabelecimento = EstabelecimentoAdapter.ToModelDomain(funcionario.Estabelecimento);
            funcionarioCommand.Usuario         = UsuarioAdapter.ToModelDomain(funcionario.Usuario);

            return(funcionarioCommand);
        }
Exemplo n.º 3
0
        public Task <HttpResponseMessage> Put(Guid id, [FromBody] dynamic body)
        {
            var funcionarioCommand = new FuncionarioCommand(
                nome: (string)body.nome,
                cpf: (string)body.cpf,
                celular: (string)body.celular,
                email: (string)body.email,
                funcao: (string)body.funcao,
                idEstabelecimento: (Guid)body.estabelecimentoId,
                imagem: (string)body.imagem
                );
            var enderecoCommand = new EnderecoCommand(
                logradouro: (string)body.endereco.logradouro,
                numero: (string)body.endereco.numero,
                complemento: (string)body.endereco.complemento,
                bairro: (string)body.endereco.bairro,
                cep: (string)body.endereco.cep,
                idCidade: (Guid)body.endereco.cidadeId,
                idEstado: (Guid)body.endereco.estadoId
                );

            funcionarioCommand.Endereco = enderecoCommand;
            funcionarioCommand.IdPessoa = id;

            var funcionario = _funcionarioApp.Atualizar(funcionarioCommand);

            return(CreateResponse(HttpStatusCode.OK, funcionario));
        }
Exemplo n.º 4
0
        public FuncionarioCommand Atualizar(FuncionarioCommand funcionarioCommand)
        {
            var funcionario = _funcionarioService.ObterPorId(funcionarioCommand.IdPessoa.Value);

            funcionario.AtualizarDados(funcionarioCommand.Nome, funcionarioCommand.CPF, funcionarioCommand.Celular,
                                       funcionarioCommand.Email, funcionarioCommand.Funcao, funcionarioCommand.Imagem);

            var funcionarioRetorno = _funcionarioService.Atualizar(funcionario);

            var endereco = _enderecoService.ObterEnderecoPorIdPessoa(funcionarioCommand.IdPessoa.Value);

            endereco.AtualizarDados(funcionarioCommand.Endereco.Logradouro, funcionarioCommand.Endereco.Numero, funcionarioCommand.Endereco.Complemento,
                                    funcionarioCommand.Endereco.Bairro, funcionarioCommand.Endereco.CidadeId, funcionarioCommand.Endereco.EstadoId,
                                    funcionarioCommand.Endereco.Cep);

            var enderecoRetorno = _enderecoService.Atualizar(endereco);

            funcionarioRetorno.AdicionarEndereco(enderecoRetorno);

            funcionarioRetorno.DefinirEstabelecimento(_estabelecimentoService.ObterPorId(funcionarioRetorno.EstabelecimentoId));

            if (Commit())
            {
                funcionarioRetorno.AnularEstabelecimento();
                return(FuncionarioAdapter.ToModelDomain(funcionarioRetorno));
            }

            return(null);
        }
        public Task <HttpResponseMessage> Post([FromBody] dynamic body)
        {
            var estabelecimentoCommand = new EstabelecimentoCommand(
                razaoSocial: (string)body.estabelecimento.razaoSocial,
                nomeFantasia: (string)body.estabelecimento.nomeFantasia,
                email: (string)body.estabelecimento.email,
                cnpj: (string)body.estabelecimento.cnpj,
                telefone: (string)body.estabelecimento.telefone,
                logo: (string)body.estabelecimento.logo,
                descricao: (string)body.estabelecimento.descricao
                );
            var enderecoJuridicoCommand = new EnderecoJuridicoCommand(
                logradouro: (string)body.estabelecimento.logradouro,
                numero: (string)body.estabelecimento.numero,
                complemento: (string)body.estabelecimento.complemento,
                bairro: (string)body.estabelecimento.bairro,
                cep: (string)body.estabelecimento.cep,
                idCidade: (Guid)body.estabelecimento.idCidade,
                idEstado: (Guid)body.estabelecimento.idEstado
                );
            var funcionarioCommand = new FuncionarioCommand(
                nome: (string)body.nome,
                cpf: (string)body.cpf,
                celular: (string)body.celular,
                email: (string)body.email,
                funcao: (string)body.funcao,
                idEstabelecimento: null,
                imagem: (string)body.imagem
                );
            var enderecoCommand = new EnderecoCommand(
                logradouro: (string)body.logradouro,
                numero: (string)body.numero,
                complemento: (string)body.complemento,
                bairro: (string)body.bairro,
                cep: (string)body.cep,
                idCidade: (Guid)body.idCidade,
                idEstado: (Guid)body.idEstado
                );
            var usuarioCommand = new UsuarioCommand(
                email: (string)body.usuario.email,
                senha: (string)body.usuario.confirmarSenha,
                perfil: (int)body.usuario.perfil,
                estaAtivo: (bool)body.usuario.estaAtivo,
                idPessoa: null
                );

            estabelecimentoCommand.EnderecoJuridico = enderecoJuridicoCommand;
            funcionarioCommand.Endereco             = enderecoCommand;
            funcionarioCommand.Estabelecimento      = estabelecimentoCommand;
            funcionarioCommand.Usuario = usuarioCommand;

            var estabelecimento = _estabelecimentoApp.Cadastrar(funcionarioCommand);

            return(CreateResponse(HttpStatusCode.Created, estabelecimento));
        }
Exemplo n.º 6
0
        public FuncionarioCommand Cadastrar(FuncionarioCommand funcionarioCommand)
        {
            var funcionario = _funcionarioService.Adicionar(FuncionarioAdapter.ToDomainModel(funcionarioCommand));

            if (Commit())
            {
                return(FuncionarioAdapter.ToModelDomain(funcionario));
            }

            return(null);
        }
Exemplo n.º 7
0
        public EstabelecimentoCommand Cadastrar(FuncionarioCommand funcionarioCommand)
        {
            var estabelecimento = _estabelecimentoService.Adicionar(EstabelecimentoAdapter.ToDomainModel(funcionarioCommand.Estabelecimento));

            funcionarioCommand.EstabelecimentoId = estabelecimento.IdPessoaJuridica;
            var funcionario = _funcionarioService.Adicionar(FuncionarioAdapter.ToDomainModel(funcionarioCommand));

            funcionarioCommand.Usuario.IdPessoa = funcionario.IdPessoa;
            var usuario = _usuarioService.Adicionar(UsuarioAdapter.ToDomainModel(funcionarioCommand.Usuario));

            if (Commit())
            {
                //TODO: Verificar objeto recursivo
                return(EstabelecimentoAdapter.ToModelDomain(estabelecimento));
            }

            return(null);
        }