Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        public bool DeleteAFriendById(int id)
        {
            bool res = false;

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

            if (connect.conectar())
            {
                res = connect.Executar(string.Format(
                                           "delete Pessoa " +
                                           " where id = {0}",
                                           id.ToString()), false);

                connect.desconectar();
            }

            return(res);
        }
Exemplo n.º 4
0
        public bool InsertFriends(FriendViewModel newFriend)
        {
            bool   result        = false;
            string dataformatada = string.Format(newFriend.BirthDate.ToString("yyyy-MM-dd"));
            string sql           = "insert into dbo.Friends " +
                                   " ( FirstName, LastName, BirthDate )" +
                                   " values " +
                                   " ('" + newFriend.FirstName + "','" + newFriend.LastName + "','" + dataformatada + "') ";

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

            BD.conectar();

            result = BD.Executar(sql, false);

            BD.desconectar();

            return(result);
        }
Exemplo n.º 5
0
        public bool UpdateAFriend(FriendViewModel friendViewModel)
        {
            bool res = false;

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

            if (Connect.conectar())
            {
                res = Connect.Executar(string.Format("update Friends " +
                                                     " set FirstName = '{0}', " +
                                                     " LastName = '{1}'," +
                                                     " BirthDate = '{2}'" +
                                                     " where FriendId = {3}",
                                                     friendViewModel.FirstName,
                                                     friendViewModel.LastName,
                                                     friendViewModel.BirthDate,
                                                     friendViewModel.FriendId), false);

                Connect.desconectar();
            }

            return(res);
        }