Esempio n. 1
0
        public ResponsavelDTO UpdateResponsavel(ResponsavelDTO responsavelDTO)
        {
            try
            {
                if (responsavelDTO == null)
                {
                    throw new ArgumentNullException("ResponsavelDTO");
                }

                if (responsavelDTO.Cpf != null)
                {
                    responsavelDTO.Cpf = responsavelDTO.Cpf.Replace("-", "").Replace(".", "").Replace("_", "").Trim();
                }
                if (responsavelDTO.Telefone != null)
                {
                    responsavelDTO.Telefone = responsavelDTO.Telefone.Replace("_", "").Replace("-", "").Trim();
                }
                if (responsavelDTO.Celular != null)
                {
                    responsavelDTO.Celular = responsavelDTO.Celular.Replace("_", "").Replace("-", "").Trim();
                }

                var persistido = _responsavelRepository.Get(responsavelDTO.Id);
                if (persistido == null)
                {
                    throw new Exception("Responsável não encontrado.");
                }

                var corrente = ResponsavelFactory.CreateResponsavel(
                    responsavelDTO.Nome,
                    responsavelDTO.Cpf,
                    responsavelDTO.Telefone,
                    responsavelDTO.Celular,
                    responsavelDTO.Email,
                    responsavelDTO.Sexo,
                    persistido.DataCadastro,
                    responsavelDTO.TipoAbertura,
                    responsavelDTO.EnviarEmail,
                    responsavelDTO.Rg,
                    responsavelDTO.EstadoCivil
                    );

                corrente.Id = persistido.Id;

                AlterarResponsavel(persistido, corrente);

                var adapter = TypeAdapterFactory.CreateAdapter();
                return(adapter.Adapt <Responsavel, ResponsavelDTO>(corrente));
            }
            catch (Exception ex)
            {
                throw ManipuladorDeExcecao.TrateExcecao(ex);
            }
        }
Esempio n. 2
0
        public ResponsavelDTO AddResponsavel(ResponsavelDTO responsavelDTO)
        {
            try
            {
                if (responsavelDTO == null)
                {
                    throw new ArgumentNullException("ResponsavelDTO");
                }

                if (responsavelDTO.Cpf != null)
                {
                    responsavelDTO.Cpf = responsavelDTO.Cpf.Replace("-", "").Replace(".", "").Replace("_", "").Trim();
                }
                if (responsavelDTO.Telefone != null)
                {
                    responsavelDTO.Telefone = responsavelDTO.Telefone.Replace("_", "").Replace("-", "").Trim();
                }
                if (responsavelDTO.Celular != null)
                {
                    responsavelDTO.Celular = responsavelDTO.Celular.Replace("_", "").Replace("-", "").Trim();
                }

                var Responsavel = ResponsavelFactory.CreateResponsavel(
                    responsavelDTO.Nome,
                    responsavelDTO.Cpf,
                    responsavelDTO.Telefone,
                    responsavelDTO.Celular,
                    responsavelDTO.Email,
                    responsavelDTO.Sexo,
                    DateTime.Now,
                    responsavelDTO.TipoAbertura,
                    responsavelDTO.EnviarEmail,
                    responsavelDTO.Rg,
                    responsavelDTO.EstadoCivil
                    );

                SalvarResponsavel(Responsavel);

                var adapter = TypeAdapterFactory.CreateAdapter();
                return(adapter.Adapt <Responsavel, ResponsavelDTO>(Responsavel));
            }
            catch (Exception ex)
            {
                throw ManipuladorDeExcecao.TrateExcecao(ex);
            }
        }