Exemple #1
0
            private static void TestProductsService()
            {
                List <Product> products = new List <Product>
                {
                    new Product()
                    {
                        Articulus    = null,
                        Name         = "M-16",
                        Color        = "Black",
                        Manufacturer = "USANavi",
                        Price        = 123.56m,
                        Quantity     = 45,
                        Sale         = null,
                        Type         = "rifle",
                        Description  = null
                    }
                };

                using (ProductsServiceClient productsclient = new ProductsServiceClient())
                {
                    //Insert
                    Console.WriteLine("1. Insert data:");
                    var cres = productsclient.Create(products[0]);
                    products[0].Articulus = (int)cres.Item2;
                    Console.WriteLine("Insert data\n");

                    //GetAll
                    Console.WriteLine("2. Viewing data:");
                    var gres = productsclient.GetAll();
                    foreach (var product in gres)
                    {
                        Console.WriteLine(product.Articulus + " " + product.Name + " " + product.Color);
                    }

                    //Update
                    Console.WriteLine("\n3. Update data:");
                    products[0].Sale     = 80;
                    products[0].Quantity = 12;
                    products[0].Color    = "Brown";
                    var ures = productsclient.Update(products);
                    Console.WriteLine(ures.Item2 + "\n");

                    //GetAll
                    Console.WriteLine("4. Viewing updated data:");
                    var gres2 = productsclient.GetAll();
                    foreach (var product in gres2)
                    {
                        Console.WriteLine(product.Articulus + " " + product.Name + " " + product.Color);
                    }

                    //Delete
                    Console.WriteLine("\n5. Deleting data:");
                    var dres = productsclient.Delete(products);
                    Console.WriteLine(dres.Item2 + "\n");

                    //GetAll
                    Console.WriteLine("6. Viewing data after delete:");
                    var gres3 = productsclient.GetAll();
                    foreach (var product in gres3)
                    {
                        Console.WriteLine(product.Articulus + " " + product.Name + " " + product.Color);
                    }
                }
            }