-
Notifications
You must be signed in to change notification settings - Fork 1
Create Job US
Chris Wallis edited this page Jun 28, 2013
·
4 revisions
using System;
using CarDeliveryNetwork.Api.ClientProxy;
using CarDeliveryNetwork.Api.Data;
using CarDeliveryNetwork.Types;
namespace ApiConsole
{
class Program
{
// Car Delivery Network API url
const string ServiceUrl = "https://go.cardeliverynetwork.com/trainingus/OpenApi"; // CDN US Training
//const string ServiceUrl = "https://go.cardeliverynetwork.com/us/OpenApi"; // CDN US
// API user's key
const string ServiceApiKey = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
static void Main(string[] args)
{
var newjob = new Job();
// Setup some basic job details
newjob.JobInitiator = "Chris Wallis";
newjob.CustomerReference = "REF123";
newjob.Notes = "These are the notes";
newjob.ServiceRequired = ServiceType.Transported;
// Setup the customer record
newjob.Customer.QuickCode = "CDN";
newjob.Customer.Contact = "Wayne Pollock";
newjob.Customer.OrganisationName = "Car Delivery Network, Inc.";
newjob.Customer.AddressLines = "7280 NW 87th Terr.";
newjob.Customer.City = "Kansas City";
newjob.Customer.StateRegion = "MO";
newjob.Customer.ZipPostCode = "64153";
newjob.Customer.Phone = "123 123 123";
newjob.Customer.Notes = "The Customer Notes";
newjob.Customer.Email = "example@example.com";
// Setup the pick-up details
newjob.Pickup.RequestedDate = DateTime.Today + TimeSpan.FromDays(1);
newjob.Pickup.RequestedDateIsExact = true;
newjob.Pickup.Destination.QuickCode = "MS";
newjob.Pickup.Destination.Contact = "Bill";
newjob.Pickup.Destination.OrganisationName = "Mirosoft";
newjob.Pickup.Destination.AddressLines = "1065 La Avenida";
newjob.Pickup.Destination.City = "Mountain View";
newjob.Pickup.Destination.StateRegion = "CA";
newjob.Pickup.Destination.ZipPostCode = "94043";
newjob.Pickup.Destination.Phone = " (650) 693-4000";
newjob.Pickup.Destination.Notes = "These are the pickup notes";
// Setup the drop-off details
newjob.Dropoff.RequestedDate = DateTime.Today + TimeSpan.FromDays(3);
newjob.Dropoff.RequestedDateIsExact = false;
newjob.Dropoff.Destination.QuickCode = "APPLE";
newjob.Dropoff.Destination.Contact = "Steve";
newjob.Dropoff.Destination.OrganisationName = "Apple";
newjob.Dropoff.Destination.AddressLines = " 1 Infinite Loop";
newjob.Dropoff.Destination.City = "Cupertino";
newjob.Dropoff.Destination.StateRegion = "CA";
newjob.Dropoff.Destination.ZipPostCode = "95014";
newjob.Dropoff.Destination.Phone = "408.996.1010";
newjob.Dropoff.Destination.Notes = "These are the drop-off notes";
// Add some vehicles
newjob.Vehicles.Add(new Vehicle()
{
Registration = "1964",
Vin = "09876543210987654",
Make = "Chevrolet",
Model = "Malibu"
});
newjob.Vehicles.Add(new Vehicle()
{
Registration = "1978",
Vin = "12345678901234567",
Make = "Ford",
Model = "Capri",
Variant = "L",
Notes = "Red"
});
try
{
// Create a client proxy
var proxy = new OpenApi(ServiceUrl, ServiceApiKey);
// Create the job
newjob = proxy.CreateJob(newjob);
// Print the job number and Id of the new job
Console.WriteLine(string.Format("Created job: {0}, Id: {1}", newjob.JobNumber, newjob.Id));
}
catch (HttpResourceFaultException ex)
{
Console.WriteLine("HttpResourceFaultException: StatusCode: {0} Message: {1}", ex.StatusCode, ex.Message);
}
catch (Exception ex)
{
Console.WriteLine("Exception: Message: {0}", ex.Message);
}
Console.ReadLine();
}
}
}