Exemple #1
0
        // string connStr = "server=localhost;port=3306;database=mydb;user=root;password="******"server=k3xio06abqa902qt.cbetxkdyhwsb.us-east-1.rds.amazonaws.com;port=3306;database=aeacqkuf3fr8uq8t;user=ss7z1t6oys987shb;password=nw473umt2r9yu41d";
        public async Task <bool> Actualizar(ClientsEntity actualizado)
        {
            var cmd = new MySqlCommand("UPDATE clients SET name = @name, lastName = @lastName, phone = @phone, email = @email WHERE id = @id");

            cmd.Parameters.AddWithValue("@id", actualizado.id);
            cmd.Parameters.AddWithValue("@name", actualizado.name);
            cmd.Parameters.AddWithValue("@lastName", actualizado.lastName);
            cmd.Parameters.AddWithValue("@phone", actualizado.phone);
            cmd.Parameters.AddWithValue("@email", actualizado.email);

            using (var conn = new MySqlConnection(GetConnectionString()))
            {
                try
                {
                    cmd.Connection = conn;
                    await cmd.Connection.OpenAsync();

                    await cmd.ExecuteNonQueryAsync();

                    return(true);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                // return false;
            }
        }
Exemple #2
0
        public async Task <bool> Guardar(ClientsEntity nuevo)
        {
            var cmd = new MySqlCommand("INSERT INTO clients (name, lastName, phone, email) VALUES (@name, @lastName, @phone, @email)");

            cmd.Parameters.AddWithValue("@name", nuevo.name);
            cmd.Parameters.AddWithValue("@lastName", nuevo.lastName);
            cmd.Parameters.AddWithValue("@phone", nuevo.phone);
            cmd.Parameters.AddWithValue("@email", nuevo.email);

            using (var conn = new MySqlConnection(GetConnectionString()))
            {
                try
                {
                    cmd.Connection = conn;
                    await cmd.Connection.OpenAsync();

                    await cmd.ExecuteNonQueryAsync();


                    return(true);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            // return false;
        }
Exemple #3
0
        private static ClientsEntity ParseClient(MySqlDataReader reader)
        {
            var c = new ClientsEntity();

            c.id       = (int)(long)reader["id"];
            c.name     = (string)reader["name"];
            c.lastName = (string)reader["lastName"];
            c.phone    = (string)reader["phone"];
            c.email    = (string)reader["email"];
            return(c);
        }