/// <summary> /// Gets the WFM Service Configured based on your requirements /// </summary> /// <param name="serviceType">The Service Type Required ("Client", "Contact" ...)</param> /// <returns>The Service, fully populated</returns> public static Object GetWcfSvc(string serviceType) { Uri serviceUri; EndpointAddress endpointAddress; var binding = BindingFactory.CreateInstance(); object service = null; string serviceBase = "http://modernpractice2013.cloudapp.net"; if (DefaultRegion == "NZ") { serviceBase = "http://modernpractice2013-nz.cloudapp.net"; } //serviceBase = "http://localhost:56019"; switch (serviceType) { case "Client": serviceUri = new Uri(serviceBase + "/ClientService.svc"); endpointAddress = new EndpointAddress(serviceUri); service = new ClientClient(binding, endpointAddress); break; case "Contact": serviceUri = new Uri(serviceBase + "/ContactService.svc"); endpointAddress = new EndpointAddress(serviceUri); service = new ContactClient(binding, endpointAddress); break; case "CustomField": serviceUri = new Uri(serviceBase + "/CustomFieldDefinitionService.svc"); endpointAddress = new EndpointAddress(serviceUri); service = new CustomFieldDefinitionClient(binding, endpointAddress); break; case "Invoice": serviceUri = new Uri(serviceBase + "/InvoiceService.svc"); endpointAddress = new EndpointAddress(serviceUri); service = new InvoiceClient(binding, endpointAddress); break; case "Job": serviceUri = new Uri(serviceBase + "/JobService.svc"); endpointAddress = new EndpointAddress(serviceUri); service = new JobClient(binding, endpointAddress); break; case "Lead": serviceUri = new Uri(serviceBase + "/LeadService.svc"); endpointAddress = new EndpointAddress(serviceUri); service = new LeadClient(binding, endpointAddress); break; case "Quote": serviceUri = new Uri(serviceBase + "/QuoteService.svc"); endpointAddress = new EndpointAddress(serviceUri); service = new QuoteClient(binding, endpointAddress); break; case "Task": serviceUri = new Uri(serviceBase + "/TaskService.svc"); endpointAddress = new EndpointAddress(serviceUri); service = new TaskClient(binding, endpointAddress); break; case "Staff": serviceUri = new Uri(serviceBase + "/StaffService.svc"); endpointAddress = new EndpointAddress(serviceUri); service = new StaffClient(binding, endpointAddress); break; case "Template": serviceUri = new Uri(serviceBase + "/TemplateService.svc"); endpointAddress = new EndpointAddress(serviceUri); service = new TemplateClient(binding, endpointAddress); break; case "Cost": serviceUri = new Uri(serviceBase + "/CostService.svc"); endpointAddress = new EndpointAddress(serviceUri); service = new CostClient(binding, endpointAddress); break; case "Supplier": serviceUri = new Uri(serviceBase + "/SupplierService.svc"); endpointAddress = new EndpointAddress(serviceUri); service = new SupplierClient(binding, endpointAddress); break; case "PurchaseOrder": serviceUri = new Uri(serviceBase + "/PurchaseOrderService.svc"); endpointAddress = new EndpointAddress(serviceUri); service = new PurchaseOrderClient(binding, endpointAddress); break; case "Time": serviceUri = new Uri(serviceBase + "/TimeService.svc"); endpointAddress = new EndpointAddress(serviceUri); service = new SupplierClient(binding, endpointAddress); break; } return(service); }
/// <summary> /// get client object with custom fields /// </summary> /// <param name="client"></param> /// <param name="accountKey"></param> /// <param name="customFieldSvc"></param> /// <param name="customFields"></param> /// <returns></returns> public static ExpandoObject GetExpandoClient(ClientSvc.Client client, string accountKey, CustomFieldDefinitionClient customFieldSvc, CustomFieldDefinition[] customFields) { dynamic expando = new ExpandoObject(); var p = expando as IDictionary <String, object>; p["Id"] = client.ID; p["Name"] = client.Name; p["Address"] = client.Address; p["Phone"] = client.Phone; p["Region"] = client.Region; p["Country"] = client.Country; p["PostalAddress"] = client.PostalAddress; p["PostalCity"] = client.PostalCity; p["PostalRegion"] = client.PostalRegion; p["PostalPostCode"] = client.PostalPostCode; p["PostalCountry"] = client.PostalCountry; p["Website"] = client.Website; p["ReferralSource"] = client.ReferralSource; p["ExportCode"] = client.ExportCode; p["IsProspect"] = client.IsProspect; p["TaxNumber"] = client.TaxNumber; p["CompanyNumber"] = client.CompanyNumber; p["BusinessNumber"] = client.BusinessNumber; p["GstRegistered"] = client.GstRegistered; var clientCustomFields = customFieldSvc.GetClientCustomFields(client.ID, accountKey); foreach (var field in customFields) { var clientField = clientCustomFields.FirstOrDefault(x => x.Name == field.Name); if (clientField != null) { p[field.Name] = GetCustomFieldValue(clientField, field.ValueElement); } else { p[field.Name] = String.Empty; } } return(p as ExpandoObject); }