/**
         * Creates a job returns outputs the job identifer
         *
         * No error checking
         *
         *
         **/
        private static void CreateAJob()
        {
            Console.WriteLine ("Please enter a job template id");
            string jobTemplateId = Console.ReadLine();
            GeopalClient geopalClient = new GeopalClient("api/jobs/createandassign");
            geopalClient.setEmployeeId(employeeId);
            geopalClient.setPrivateKey(privateKey);

            NameValueCollection pairs = new NameValueCollection();
            pairs.Add("template_id", jobTemplateId);
            String response = geopalClient.post(pairs);

            GeopalRequestJob geopalRequestJob = JsonConvert.DeserializeObject<GeopalRequestJob>(response);
            Console.WriteLine("Created Job With Identifier = "+geopalRequestJob.job.identifier);
            Console.WriteLine("Created Job With Id = "+geopalRequestJob.job.id);
        }
 /**
  * Reads in jobs over a date range
  *
  * Note error checking
  *
  *
  **/
 private static void ReadJobsDateRange()
 {
     Console.WriteLine ("Please enter a from date (yyyy-MM-dd HH:mm:ss) see http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx");
     string dateTimeFrom = Console.ReadLine ();
     dateTimeFrom = HttpUtility.UrlEncode(dateTimeFrom);
     Console.WriteLine ("Please enter a to date (yyyy-MM-dd HH:mm:ss)");
     string dateTimeTo = Console.ReadLine ();
     dateTimeTo = HttpUtility.UrlEncode(dateTimeTo);
     GeopalClient geopalClient = new GeopalClient ("api/jobsearch/ids");
     geopalClient.setEmployeeId (employeeId);
     geopalClient.setPrivateKey (privateKey);
     String response = geopalClient.get ("date_time_from=" + dateTimeFrom + "&date_time_to=" + dateTimeTo);
     GeopalRequestJobIds geopalRequestJobIds = JsonConvert.DeserializeObject<GeopalRequestJobIds> (response);
     foreach (JobJustId jobJustId in geopalRequestJobIds.jobs) {
         Console.WriteLine("Job Id: " + jobJustId.id);
         ReadAJob(jobJustId.id);
     }
 }
        /**
         *  Shows in detail a job template
         *
         * No error checking
         *
         *
         **/
        private static void ReadTemplate()
        {
            Console.WriteLine ("Please enter a job template id");
            string jobTemplateId = Console.ReadLine();
            GeopalClient geopalClient = new GeopalClient("api/jobtemplates/get");
            geopalClient.setEmployeeId(employeeId);
            geopalClient.setPrivateKey(privateKey);
            String response = geopalClient.get("template_id="+jobTemplateId);
            GeopalRequestJobTemplate geopalRequestJobTemplate = JsonConvert.DeserializeObject<GeopalRequestJobTemplate>(response);
            Console.WriteLine("Job Template Name = " + geopalRequestJobTemplate.job_template.name);
            Console.WriteLine("\nJob Fields");
            foreach(JobTemplateField jobTemplateField in geopalRequestJobTemplate.job_template.job_template_fields) {
                Console.WriteLine(jobTemplateField.name + " (" + jobTemplateField.id + ")" );
            }

            Console.WriteLine("\nJob Workflows");
            foreach(JobTemplateWorkflow jobTemplateWorkflow in geopalRequestJobTemplate.job_template.job_template_workflows) {
                Console.WriteLine(jobTemplateWorkflow.name + " (" + jobTemplateWorkflow.id + ") ["+jobTemplateWorkflow.action+"]" );
            }
        }
 /**
  * Reads in employee shifts via date range, matches on shift start date time
  */
 private static void ReadInEmployeeShiftsDateRange()
 {
     Console.WriteLine ("Please enter a from date (yyyy-MM-dd HH:mm:ss) see http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx");
     string dateTimeFrom = Console.ReadLine ();
     dateTimeFrom = HttpUtility.UrlEncode(dateTimeFrom);
     Console.WriteLine ("Please enter a to date (yyyy-MM-dd HH:mm:ss)");
     string dateTimeTo = Console.ReadLine ();
     dateTimeTo = HttpUtility.UrlEncode(dateTimeTo);
     GeopalClient geopalClient = new GeopalClient ("api/employees/shifts");
     geopalClient.setEmployeeId (employeeId);
     geopalClient.setPrivateKey (privateKey);
     String response = geopalClient.get ("date_time_from=" + dateTimeFrom + "&date_time_to=" + dateTimeTo);
     GeopalRequestEmployeesShifts geopalRequestEmployeesShifts = JsonConvert.DeserializeObject<GeopalRequestEmployeesShifts> (response);
     foreach (Shift shift in geopalRequestEmployeesShifts.shifts) {
         Console.WriteLine("Employee Id: " + shift.employee_id);
         Console.WriteLine("Start Date: " + shift.start_on);
         Console.WriteLine("Shift Duration: " + shift.duration);
     }
 }
        private static void ReadAJob(string jobId)
        {
            GeopalClient geopalClient = new GeopalClient("api/jobs/get");
            geopalClient.setEmployeeId(employeeId);
            geopalClient.setPrivateKey(privateKey);
            String response = geopalClient.get("job_id="+jobId);
            GeopalRequestJob geopalRequestJob = JsonConvert.DeserializeObject<GeopalRequestJob>(response);
            Console.WriteLine("Job Identifier: "+geopalRequestJob.job.identifier);
            Console.WriteLine("Job Template: "+geopalRequestJob.job.job_template.name);

            Console.WriteLine("\nJob Fields");
            foreach(JobField jobField in geopalRequestJob.job.job_fields) {
                Console.WriteLine(jobField.name + " (" + jobField.id + "): " + jobField.action_value_entered );
            }

            Console.WriteLine("\nJob Workflows");
            foreach(JobWorkflow jobWorkflow in geopalRequestJob.job.job_workflows) {
                Console.WriteLine(jobWorkflow.name + " (" + jobWorkflow.id + "): " + jobWorkflow.action_value_entered );
                foreach(JobWorkflowFile jobWorkflowFile in jobWorkflow.job_workflow_files) {
                    Console.WriteLine(jobWorkflowFile.file_name + " (" + jobWorkflowFile.id + "): s3 file id " + jobWorkflowFile.s3file_id );
                    DownloadS3File(jobWorkflowFile.s3file_id);
                }
            }
        }
 /**
  * Lists all job templates on your account
  *
  * No error checking
  *
  *
  **/
 private static void ListTemplates()
 {
     GeopalClient geopalClient = new GeopalClient("api/jobtemplates/all");
     geopalClient.setEmployeeId(employeeId);
     geopalClient.setPrivateKey(privateKey);
     String response = geopalClient.get();
     GeopalRequestJobTemplates geopalRequestJobTemplates = JsonConvert.DeserializeObject<GeopalRequestJobTemplates>(response);
     foreach(JobTemplateSimple jobTemplateSimple in geopalRequestJobTemplates.job_templates) {
         if (jobTemplateSimple.is_deleted == false) {
             Console.WriteLine(jobTemplateSimple.name + " (" + jobTemplateSimple.job_template_id + ")" );
         }
     }
 }
 /**
  * Shows a list of current active employees, or converts json output to xml as an example
  *
  * No error checking
  *
  **/
 private static void ListEmployess(bool convert2Xml = false)
 {
     GeopalClient geopalClient = new GeopalClient ("api/employees/all");
     geopalClient.setEmployeeId (employeeId);
     geopalClient.setPrivateKey (privateKey);
     String response = geopalClient.get ();
     if (convert2Xml) {
         XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(response, "employees");
         Console.WriteLine(doc.OuterXml);
     } else {
         GeopalRequestEmployees geopalRequestEmployees = JsonConvert.DeserializeObject<GeopalRequestEmployees> (response);
         foreach (Employee employee in geopalRequestEmployees.employees) {
             Console.WriteLine(employee.first_name + " " + employee.last_name + " (" + employee.id + ") " + employee.address);
         }
     }
 }
 /**
  * Simple function to download a an s3 file, note tmp dir is hardcoded, file name is hardcoded
  *
  * No error checking
  *
  *
  **/
 private static void DownloadS3File(int s3fileId)
 {
     GeopalClient geopalClient = new GeopalClient("api/s3files/get");
     geopalClient.setEmployeeId(employeeId);
     geopalClient.setPrivateKey(privateKey);
     geopalClient.downloadFile("s3_file_id="+s3fileId, "/tmp/" + s3fileId + ".jpg");
 }