Exemple #1
0
        public List <ContatosModel> Getrecord()

        {
            ContatosDAL contatosDAL = new ContatosDAL();

            DataSet ds = contatosDAL.Getrecord();

            List <ContatosModel> usuarios = new List <ContatosModel>();

            foreach (DataRow dr in ds.Tables[0].Rows)

            {
                usuarios.Add(new ContatosModel

                {
                    ID        = Convert.ToInt32(dr["ID"]),
                    Nome      = dr["Nome"].ToString(),
                    Telefone  = dr["telefone"].ToString(),
                    Telefone2 = dr["telefone2"].ToString(),
                    Telefone3 = dr["telefone3"].ToString(),

                    Email  = dr["Email"].ToString(),
                    Email2 = dr["Email2"].ToString(),
                    Email3 = dr["Email3"].ToString(),

                    Empresa = dr["Empresa"].ToString(),

                    Endereco = dr["Endereco"].ToString(),
                });
            }
            return(usuarios.OrderBy(x => x.Nome).ToList());
        }
        public void Alterar(Contatos contato, out int retval)
        {
            if (contato.Nome.Trim().Length == 0)
            {
                throw new Exception("O Nome do Contato é Obrigatório");
            }

            ContatosDAL obj = new ContatosDAL();

            obj.Alterar(contato, conStr, out retval);
        }
        public void Excluir(int pId, out int retval)
        {
            if (pId < 1)
            {
                throw new Exception("Selecione antes de excluir.");
            }

            ContatosDAL obj = new ContatosDAL();

            obj.DELETE(pId, conStr, out retval);

            if (retval > 0)
            {
                EmailDAL objEmail = new EmailDAL();
                objEmail.DELETE(pId, conStr, out retval);

                TelefoneDAL objTel = new TelefoneDAL();
                objTel.DELETE(pId, conStr, out retval);
            }
        }