Example #1
0
        public void GetById()
        {
            TableAPIClient <sys_user> client = new TableAPIClient <sys_user>("sys_user", "yourInstance", "user", "pass");

            var retreivedUser = client.GetById("g46h5f15n11239862332v43238f382104");

            if (retreivedUser.IsError)
            {
                Assert.Fail(retreivedUser.ErrorMsg);
            }
            Assert.AreEqual("012345", retreivedUser.Result.employee_number);
        }
        static void basicOperations()
        {
            TableAPIClient <sys_user> userClient = new TableAPIClient <sys_user>("sys_user", myInstance, instanceUserName, instancePassword);

            // Deomstrate the Create (POST) operation:
            var createdUser = userClient.Post(new sys_user()
            {
                employee_number = "012345",
                first_name      = "Tester",
                last_name       = "McTester",
                email           = "*****@*****.**",
                phone           = "",
                // You can use Name instead of sys_id, but if service now does not find your value it will ignore it without any warning.
                location = new ResourceLink()
                {
                    value = "VISALIA COURTHOUSE"
                }
            });

            Console.WriteLine("User Created: " + createdUser.Result.first_name + " " + createdUser.Result.last_name + " (" + createdUser.Result.sys_id + ")");


            // Deonstrate the GetById (GET) operation:
            var retrievedUser = userClient.GetById(createdUser.Result.sys_id);

            Console.WriteLine("User Retrieved: " + retrievedUser.Result.first_name + " " + retrievedUser.Result.last_name + " (" + retrievedUser.Result.sys_id + ")");
            Console.WriteLine("              : eMail: " + retrievedUser.Result.email);
            Console.WriteLine("              : Location: " + retrievedUser.Result.Location_name);


            // Demonstrate Update (PUT) operation:
            Console.WriteLine("\n\nUpdating User");
            if (retrievedUser.Result != null)
            {
                var d = retrievedUser.Result;
                d.email = "*****@*****.**";

                // Set the location using the Guid of a good location, otherwise handle it.
                try
                {
                    d.location = new ResourceLink()
                    {
                        value = findLocationId("VISALIA DISTRICT OFFICE")
                    };
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Unable to set new user location: " + ex.Message);
                }

                var updatedUser = userClient.Put(d);
                Console.WriteLine("              : eMail: " + updatedUser.Result.email);
                Console.WriteLine("              : Location: " + updatedUser.Result.Location_name);
            }


            // Domonstrate Delete operation
            Console.Write("\n\nDeleting User");
            userClient.Delete(retrievedUser.Result.sys_id);
            Console.WriteLine("...Done");
        }