Example #1
0
        public List <FriendViewModel> GetOneFriendByName(string name)
        {
            List <FriendViewModel> lista    = new List <FriendViewModel>();
            FriendViewModel        auxiliar = new FriendViewModel();
            DataTable dataTable             = new DataTable();

            Conexao.Conexao conect = new Conexao.Conexao();
            conect.string_conexao = stringDeConexao;

            if (conect.conectar())
            {
                conect.Executar("select * " +
                                "from Friends " +
                                "where " +
                                "FirstName like '%" + name + "%'", true);

                dataTable = conect.GetData("Friends");

                conect.desconectar();
            }

            foreach (DataRow dr in dataTable.Rows)
            {
                auxiliar.FriendId  = (int)dr["FriendId"];
                auxiliar.FirstName = dr["FirstName"].ToString();
                auxiliar.LastName  = dr["LastName"].ToString();
                auxiliar.BirthDate = DateTime.Parse(dr["BirthDate"].ToString());

                lista.Add(auxiliar);
            }
            return(lista);
        }
Example #2
0
        public List <FriendViewModel> GetAllFriends()
        {
            List <FriendViewModel> lst = new List <FriendViewModel>();
            FriendViewModel        aux = new FriendViewModel();
            DataTable dt = new DataTable();

            Conexao.Conexao banco = new Conexao.Conexao();
            banco.string_conexao = stringDeConexao;

            if (banco.conectar())
            {
                banco.Executar("select * " +
                               "from Friends", true);

                dt = banco.GetData("Friends");

                banco.desconectar();
            }

            foreach (DataRow dr in dt.Rows)
            {
                aux           = new FriendViewModel();
                aux.FriendId  = (int)dr["FriendId"];
                aux.FirstName = dr["FirstName"].ToString();
                aux.LastName  = dr["LastName"].ToString();
                aux.BirthDate = DateTime.Parse(dr["BirthDate"].ToString());

                lst.Add(aux);
            }
            return(lst);
        }