private static FleetCustomer CreateCustomer()

in FMLab/Odata4ConsoleApplication/Program.cs [121:171]


        private static FleetCustomer CreateCustomer()
        {

            Console.WriteLine("Enter First Name, and then press Enter");
            string firstName = Console.ReadLine();

            Console.WriteLine("Enter Last Name, and then press Enter ");
            string lastName = Console.ReadLine();

            Random rnd = new Random();

            //Create the Customer object with the first and last names provided by the user
            FleetCustomer newCustomer = new FleetCustomer()
            {
                FirstName = firstName,
                LastName = lastName,
                DriverLicense = "B923-2381-" + rnd.Next(1000,7000).ToString(),
                CellPhone = "0123456789",
                Email = "test@contoso.com",
            };

            //Add the new customer object to the DataServiceContext object
            context.AddToFleetCustomers(newCustomer);

            //Save the DataServiceContext object and an internally a POST call is made to the OData Customer entity.
            //Record is created in Rainier Database
            Microsoft.OData.Client.DataServiceResponse response = null;
            try
            {                 
                response = context.SaveChanges(); 
            }
            catch (DataServiceRequestException e)
            {
                Console.WriteLine("Error occured while saving. Error Details: " + e.InnerException.Message);
            }

            //the following code retrieves the location header which represents the newly created entity
            foreach (ChangeOperationResponse r in response)
            {
                if (r.Headers.ContainsKey("Location"))
                {
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("New customer created: ");
                    Console.WriteLine(r.Headers["Location"]);
                }
            }

            Console.ForegroundColor = ConsoleColor.White;

            return newCustomer;
        }