Esempio n. 1
0
        private List <Customer> GetCustomers()
        {
            WebApplication2.Models.CustomerContact cont = new WebApplication2.Models.CustomerContact()
            {
                email     = "*****@*****.**",
                firstName = "first",
                lastName  = "last 1"
                            //  customer=cust
            };
            WebApplication2.Models.CustomerContact cont2 = new WebApplication2.Models.CustomerContact()
            {
                email     = "*****@*****.**",
                firstName = "first 2",
                lastName  = "last 2"
            };

            var ll  = new List <CustomerContact>();
            var ll2 = new List <CustomerContact>();

            ll.Add(cont);
            ll2.Add(cont2);

            var testCustomers = new System.Collections.Generic.List <Customer>();

            testCustomers.Add(new Customer
            {
                customerContact   = ll,
                NumberOfEmployees = 45,
                Title             = "IT department"
            });
            testCustomers.Add(new Customer
            {
                customerContact   = ll2,
                NumberOfEmployees = 45,
                Title             = "IT department"
            });

            return(testCustomers);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var    client = new HttpClient();
            string url    = "http://*****:*****@gmail.com",
                firstName = "anna",
                lastName  = "anna"
                            //  customer=cust
            };
            WebApplication2.Models.CustomerContact cont2 = new WebApplication2.Models.CustomerContact()
            {
                email     = "*****@*****.**",
                firstName = "nikos",
                lastName  = "nikos"
            };


            var ll = new List <CustomerContact>();

            ll.Add(cont);
            ll.Add(cont2);

            //  cust.customerContact = ll;

            WebApplication2.Models.Customer cust = new WebApplication2.Models.Customer()
            {
                customerContact   = ll,
                NumberOfEmployees = 33,
                Title             = "president"
            };

            HttpResponseMessage response = new HttpResponseMessage();

            switch (int.Parse(choice))
            {
            case 1:
                response = client.GetAsync(url).Result;
                WebApplication2.Models.Customer[] data = JsonConvert.DeserializeObject <WebApplication2.Models.Customer[]>(response.Content.ReadAsStringAsync().Result);

                break;

            case 2:
                response = client.PostAsJsonAsync <WebApplication2.Models.Customer>(url, cust).Result;
                Console.WriteLine(response.ToString());
                break;

            case 3:
                response = client.PostAsJsonAsync(url, cust).Result;
                Console.WriteLine(response.ToString());
                break;
                //case 4:
                // response = client.DeleteAsync()
            }
        }