示例#1
0
        public static ParceiroNegocioPessoaFisica Save(ParceiroNegocioPessoaFisica entity)
        {
            using (var transaction = NHibernateHttpModule.Session.BeginTransaction())
            {
                try
                {
                    if (PessoaFisicaRepository.ExisteCpf(entity))
                    {
                        throw new Exception("Já existe um CPF cadastrado");
                    }
                    if (Validate(entity))
                    {
                        if (!string.IsNullOrEmpty(entity.Senha))
                        {
                            entity.Senha = Criptografia.CriptografarSenha(entity.Senha);
                        }

                        NHibernateHttpModule.Session.Save(entity);
                        transaction.Commit();
                    }
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    throw;
                }
            }

            return(entity);
        }