public static List <CreateMarca> GetMarca(int id)
        {
            string connString = "Server=tabasserver.postgres.database.azure.com; User Id=chanchus@tabasserver; Database=TabasDB; Port=5432; Password=Password1;SSLMode=Prefer";

            using (var conn = new NpgsqlConnection(connString))
            {
                Console.Out.WriteLine("Opening connection");
                conn.Open();

                string query = "SELECT * FROM marcabagcart WHERE id='@id'";

                query = query.Replace("@id", id.ToString());


                using (var command = new NpgsqlCommand(query, conn))
                {
                    var reader = command.ExecuteReader();
                    List <CreateMarca> listamarca = new List <CreateMarca>();

                    while (reader.Read())
                    {
                        CreateMarca marca = null;
                        marca            = new CreateMarca();
                        marca.tmarca     = reader.GetValue(0).ToString();
                        marca.tmodelo    = Convert.ToInt32(reader.GetValue(1));
                        marca.tcapacidad = Convert.ToInt32(reader.GetValue(2));
                        listamarca.Add(marca);
                    }

                    return(listamarca);
                }
            }
        }
Esempio n. 2
0
 public bool Post(CreateMarca marca)
 {
     if (marca != null)
     {
         return CreateMarcaRepository.addMarca(marca);
     }
     else
     {
         return false;
     }
 }
        public static bool addMarca(CreateMarca marca)
        {
            string connString = "Server=tabasserver.postgres.database.azure.com; User Id=chanchus@tabasserver; Database=TabasDB; Port=5432; Password=Password1;SSLMode=Prefer";


            using (var conn = new NpgsqlConnection(connString))
            {
                Console.Out.WriteLine("Opening connection");
                conn.Open();
                using (var command = new NpgsqlCommand("SELECT CreateMarca(@Tmarca, @TModelo, @TCapacidad)", conn))
                {
                    command.Parameters.AddWithValue("@TMarca", marca.tmarca);
                    command.Parameters.AddWithValue("@TModelo", marca.tmodelo);
                    command.Parameters.AddWithValue("@TCapacidad", marca.tcapacidad);


                    int nRows = command.ExecuteNonQuery();
                    Console.Out.WriteLine(String.Format("Number of rows updated={0}", nRows));

                    return(true);
                }
            }
        }