Ejemplo n.º 1
0
        public void AddCustomer(string firstName, string lastName)
        {
            CustomerServiceClient customerServiceClient = new CustomerServiceClient();
            try
            {
                customerServiceClient.AddCustomer(new AddCustomerRequest
                                                      {
                                                          CustomerDto = new CustomerDto
                                                                            {
                                                                                FirstName = firstName,
                                                                                LastName = lastName
                                                                            }

                                                      });
            }
            catch (Exception exception)
            {
                string message = string.Format("An error occured while in type :{0} , method :{1} ", "CustomerServiceManager", MethodBase.GetCurrentMethod().Name);
                CommonLogManager.Log.Error(message, exception);
                throw;
            }
            finally
            {
                customerServiceClient.Close();
            }
        }
Ejemplo n.º 2
0
        private static void AddCustomer()
        {
            try
            {
                using (CustomerServiceClient client = new CustomerServiceClient())
                {
                    int index = client.AddCustomer(new Customer
                    {
                        CustomerId   = 101,
                        CustomerName = "Anish",
                        City         = "Kolkata",
                        State        = "West Bengal"
                    });
                    Console.WriteLine("{0}", index);
                }
            }

            // == Using normal exception and Fault exception ==
            //catch (Exception ex)
            //{
            //    Console.ForegroundColor = ConsoleColor.Red;
            //    Console.WriteLine(ex.Message);
            //    Console.ForegroundColor = ConsoleColor.White;
            //}

            catch (FaultException <InvalidCustomerEntry> ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("{0}:{1}", ex.Detail.ErrorCode, ex.Detail.ErrorMessage);
                Console.ForegroundColor = ConsoleColor.White;
            }
        }
Ejemplo n.º 3
0
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            CustomerServiceClient proxy = new CustomerServiceClient("BasicHttpBinding_CustomerService");


            proxy.AddCustomer(txtCustomerId.Text, txtCompnayName.Text, txtAddress.Text, txtCity.Text);
        }
Ejemplo n.º 4
0
        protected override void Configure()
        {
            container = new SimpleContainer();

            var hubConnection = new HubConnectionBuilder().WithUrl(
                "http://localhost:5000/customerhub")
                                .Build();

            hubConnection.Closed += async e =>
            {
                Console.WriteLine(e);
                await Task.Delay(new Random().Next(0, 5) * 1000);

                await hubConnection.StartAsync();
            };

            hubConnection.StartAsync().GetAwaiter().GetResult();

            var customerServiceClient = new CustomerServiceClient("BasicHttpBinding_ICustomerService");

            container.Singleton <IWindowManager, WindowManager>();
            container.Singleton <IEventAggregator, EventAggregator>();
            container.RegisterInstance(typeof(ICustomerService), null, customerServiceClient);
            container.RegisterInstance(typeof(HubConnection), null, hubConnection);

            container.PerRequest <ShellViewModel>();
        }
Ejemplo n.º 5
0
        private void btnLoad_Click(object sender, RoutedEventArgs e)
        {
            using (CustomerServiceClient serviceClient = new CustomerServiceClient())
            {
                serviceClient.Open();

                Customer customer = serviceClient.GetCustomer(int.Parse(this.txtId.Text));
                this.txtName.Text = customer.Name;
                this.txtStartDate.Text = customer.StartDate.ToShortDateString();
                this.txtCreditLimit.Text = customer.CreditLimit.ToString();
                this.imgLogo.Source = ImageFromBuffer(customer.Logo);

                IExtensibleDataObject extendedCustomer = customer as IExtensibleDataObject;
                if (extendedCustomer != null)
                {
                    //ES - ordinarily the data signature is hidden from the client,
                    //and cannot be modified; access with reflection to display it:
                    object dataSiganture = ExtensionDataHelper.GetExtensionDataMemberValue(extendedCustomer, "dataSignature");
                    this.lblDataSignature.Content = string.Format("Data Signature: {0}", dataSiganture);
                }

                this.CurrentCustomer = customer;

                serviceClient.Close();
            }
        }
Ejemplo n.º 6
0
        private async void bCreate_Click(object sender, RoutedEventArgs e)
        {
            CustomerServiceClient customerServiceClient = new CustomerServiceClient();

            txtAddress.IsEnabled = false;
            txtEmail.IsEnabled = false;
            bCreate.IsEnabled = false;

            try
            {
                await customerServiceClient.CreateCustomerAsync(new CreateCustomerModel
                {
                    Address = txtAddress.Text,
                    EmailAddress = txtEmail.Text
                });
                txtAddress.Text = string.Empty;
                txtEmail.Text = string.Empty;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                txtAddress.IsEnabled = true;
                txtEmail.IsEnabled = true;
                bCreate.IsEnabled = true;
            }

        }
 public Customer GetCustomer(int customerId)
 {
     using (var customerClient = new CustomerServiceClient())
     {
         return(customerClient.GetCustomer(customerId));
     }
 }
        static void Main(string[] args)
        {
            try
            {
                var proxy = new CustomerServiceClient();

                //proxy.RegisterCustomer(new Customer { BillAmount = 560, BillDate = DateTime.Now.AddDays(-234), CustomerID = 111, CustomerName = "Phaniraj", CustomerPhone = 23434355 });


                var tcpProxy = new InternalCustomerServiceClient();
                tcpProxy.RegisterCustomer(new Customer {
                    BillAmount = 650, BillDate = DateTime.Now.AddDays(-34), CustomerID = 112, CustomerName = "Tom Sawyer", CustomerPhone = 234244555
                });

                var data = proxy.GetAllCustomers();
                foreach (var cst in data)
                {
                    Console.WriteLine($"{cst.CustomerName} with {cst.CustomerPhone} billed on {cst.BillDate.ToShortDateString()}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 9
0
        public Customer()
        {
            InitializeComponent();
            CustomerServiceClient client = new CustomerServiceClient();
            String sessionId             = (String)App.Current.Properties[App.sessionPropertyName];

            CustomersDataGrid.ItemsSource = client.FindAll(sessionId);
        }
Ejemplo n.º 10
0
        public ActionResult Register()
        {
            CustomerServiceClient territory = new CustomerServiceClient();
            IEnumerable <kaspi.lab.CustomerService.TerritoryDTO> territories = territory.GetTerritories();

            ViewBag.Terr = territories;
            return(View());
        }
Ejemplo n.º 11
0
 private static void GetCusotmer()
 {
     using (CustomerServiceClient client = new CustomerServiceClient())
     {
         Customer cust = client.GetCustomer(102);
         Console.WriteLine("{0}", cust.CustomerName);
     }
 }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client  = new CustomerServiceClient(channel);

            var response      = client.GetAllCustomers(new Empty());
            var firstCustomer = response.Customers.FirstOrDefault();
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            try
            {
                var AUTHKEY = "";
                Int32 itr_count = 0;
                var customerServiceClient = new CustomerServiceClient();
                System.Diagnostics.Debug.Write("Created Customer Client!\n");
                var filename = @"Z:\SolidWasteManagement\AMCS\ExportCustomers\MostCustomers.csv";

                //CustomerSiteLocationEntity[] customer_sites = customerServiceClient.GetCustomerSites(AUTHKEY, 100);
                //System.Diagnostics.Debug.Write(customer_sites[0].Address5+"\n");
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(filename))
                {
                    while (itr_count <150 )
                    {
                        CustomerPartialEntity[] exported_customers = customerServiceClient.ExportCustomers(AUTHKEY, 100);
                        if (exported_customers.Length <= 0) break;
                        // CustomerSiteLocationEntity[] customer_sites = customerServiceClient.GetCustomerSites(AUTHKEY,100);
                        IList<Guid> customerIds = new List<Guid>();
                        IList<Guid> customerSiteIds = new List<Guid>();

                        //filename = @"Z:\SolidWasteManagement\AMCS\ExportCustomers\Customers" + itr_count.ToString() + ".csv";

                        foreach (var customer in exported_customers)
                        {
                            customerIds.Add(customer.GUID.Value);
                            foreach (var site in customer.CustomerSites)
                            {
                                customerSiteIds.Add(site.GUID.Value);
                                String address = site.HouseNumber + " " + site.Address1 + ", " + site.Address3 + ", " + site.Address4+", "+site.Postcode;
                                //+"|"+ site.UniqueReference
                                file.WriteLine(customer.GUID.ToString() + "|" + customer.CustomerName + "|" + customer.CustomerStateId.ToString() + "|" + site.GUID.ToString() + "|" + address);
                            }

                        }
                        if (customerIds.Count > 0)
                        {
                            customerServiceClient.ExportCustomers_Complete(AUTHKEY, customerIds.ToArray());
                        }
                        if (customerSiteIds.Count > 0)
                        {
                            customerServiceClient.ExportCustomerSites_Complete(AUTHKEY, customerSiteIds.ToArray());
                        }
                        System.Diagnostics.Debug.Write("Succesfully exported customers!\n");
                        itr_count++;
                    }
                }

                customerServiceClient.Close();
                System.Diagnostics.Debug.Write("Client closed.\n");

            }
            catch (FaultException ex)
            {
                System.Diagnostics.Debug.Write(string.Format("Failed to export customers. - {0}", ex.Message));
            }
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            CustomerServiceClient client = new CustomerServiceClient();
            var result = client.GetMonths(10);

            Console.WriteLine("Months:{0}", result);

            Console.ReadKey();
        }
Ejemplo n.º 15
0
        void OnClick(object sender, EventArgs args)
        {
            CustomerServiceClient proxy = new CustomerServiceClient();

            proxy.CountUsersCompleted += new EventHandler<CountUsersCompletedEventArgs>(proxy_CountUsersCompleted);
            proxy.CountUsersAsync();

            proxy.GetUserCompleted += new EventHandler<GetUserCompletedEventArgs>(proxy_GetUserCompleted);
            proxy.GetUserAsync(1);
        }
Ejemplo n.º 16
0
        private async void bObtainList_Click(object sender, RoutedEventArgs e)
        {
            CustomerServiceClient customerServiceClient = new CustomerServiceClient();

            IEnumerable<CustomerModel> customers = await customerServiceClient.AllCustomersAsync();

            (DataContext as CustomerListViewModel).DataSource = customers.Select(c => new CustomerViewModel
            { 
                Number = c.Number, 
                Address = c.Address, 
                Email = c.EmailAddress 
            });
        }
Ejemplo n.º 17
0
 protected void Page_Load(object sender, EventArgs e)
 {
     var proxy = new CustomerServiceClient();
     try
     {
         CustomersDropDownList.DataSource = proxy.GetCustomers();
         CustomersDropDownList.DataBind();
     }
     catch (Exception exp)
     {
         ShowAlert("Error fetching customers: " + exp.Message);
     }
 }
Ejemplo n.º 18
0
        private void UpdateButton_Click(object sender, RoutedEventArgs e)
        {
            var proxy = new CustomerServiceClient();
            var cust = CustomersComboBox.SelectedItem as Customer;
            cust.ChangeTracker.State = ObjectState.Modified;

            proxy.SaveCustomerCompleted += (s, args) =>
            {
                var opStatus = args.Result;
                string msg = (opStatus.Status) ? "Customer Updated!" : 
                                "Unable to update Customer: " + opStatus.Message;
                MessageBox.Show(msg);                 
            };
            proxy.SaveCustomerAsync(cust);
        }
 public bool UpdateRecord(MessageAction action, Customer customer)
 {
     string cardNumber = customer.CreditCardNumber;
     var encryptor = new CreditCardEncryption();
     customer.CreditCardNumber = encryptor.Encrypt(cardNumber);
     try
     {
         using (var client = new CustomerServiceClient())
         {
             client.Open();
             return client.UpdateRecord(action, customer);
         }
     }
     finally
     {
         customer.CreditCardNumber = cardNumber;
     }
 }
Ejemplo n.º 20
0
 public void GetCustomers(Action<GetCustomersResponse, Exception> callback)
 {
     CustomerServiceClient customerServiceClient = new CustomerServiceClient();
     try
     {
         customerServiceClient.GetCustomersCompleted += (s, e) => callback(e.Result, e.Error);
         customerServiceClient.GetCustomersAsync();
     }
     catch (Exception exception)
     {
         string message = string.Format("An error occured while in type :{0} , method :{1} ", "CustomerServiceManager", MethodBase.GetCurrentMethod().Name);
         CommonLogManager.Log.Error(message, exception);
         throw;
     }
     finally
     {
         customerServiceClient.Close();
     }
 }
 public Customer FindRecord(string customerNumber)
 {
     var encryptor = new CreditCardEncryption();
     var customer = new Customer();
     try
     {
         using (var client = new CustomerServiceClient())
         {
             client.Open();
             customer = client.FindRecord(customerNumber);
             return customer;
         }
     }
     finally
     {
         if (customer != null)
             customer.CreditCardNumber = encryptor.Decrypt(customer.CreditCardNumber);
     }
 }
Ejemplo n.º 22
0
 private void CustomerForm_Load(object sender, EventArgs e)
 {
     _Proxy = new CustomerServiceClient();
     try
     {
         _Proxy.GetCustomersCompleted += (s, args) =>
             {
                 var custs = args.Result;
                 if (custs != null)
                     SetBindings(custs);
                 else
                     ShowMessageBox("No customers found.");
             };
         _Proxy.GetCustomersAsync();
     }
     catch (Exception exp)
     {
         ShowMessageBox("Error fetching customers: " + exp.Message);
     }
 }
Ejemplo n.º 23
0
 private void DeleteButton_Click(object sender, RoutedEventArgs e)
 {
     var proxy = new CustomerServiceClient();
     var cust = CustomersComboBox.SelectedItem as Customer;
     cust.ChangeTracker.State = ObjectState.Deleted;
     proxy.SaveCustomerCompleted += (s, args) =>
     {
         OperationStatus opStatus = args.Result;
         if (opStatus.Status)
         {
             ((ObservableCollection<Customer>)CustomersComboBox.ItemsSource).Remove(cust);
             MessageBox.Show("Customer deleted!");
         }
         else
         {
             MessageBox.Show("Unable to delete Customer: " + opStatus.Message);
         }
     };
     proxy.SaveCustomerAsync(cust);
 }
Ejemplo n.º 24
0
 public void UpdateCustomer(CustomerDto customerDto)
 {
     CustomerServiceClient customerServiceClient = new CustomerServiceClient();
     try
     {
         customerServiceClient.UpdateCustomer(new UpdateCustomerRequest
                                                  {
                                                      CustomerDto = customerDto
                                                  });
     }
     catch (Exception exception)
     {
         string message = string.Format("An error occured while in type :{0} , method :{1} ", "CustomerServiceManager", MethodBase.GetCurrentMethod().Name);
         CommonLogManager.Log.Error(message, exception);
         throw;
     }
     finally
     {
         customerServiceClient.Close();
     }
 }
Ejemplo n.º 25
0
        static void Main(string[] args)
        {
            var AUTHKEY = "";
            //Create an list of Locations to be added
            List<CustomerSiteLocationPartialEntity> locations = new List<CustomerSiteLocationPartialEntity>(); //Partial Entity instead?

            //var customerID =
            //generate new guids for the new customer to be referenced when we create a new location entity
            var customerGuid = Guid.NewGuid();
            var customerSiteGuid = Guid.NewGuid();
            System.Diagnostics.Debug.Write(customerSiteGuid + "\n");
            var siteOrderGuid = Guid.NewGuid();
            var customerSiteContainerGuid = Guid.NewGuid();
            var customerSiteRouteAssignmentGuid = Guid.NewGuid();
            /*            //Create Location To Add
            var customerSiteLocation = new CustomerSiteLocationPartialEntity {
                Address1 = "Main Street",
                Address2 = "",
                Address3 = "4234234.4234234.234234",
                Address4 = "South Bend",
                Address5 = "",
                AlternativeSearchReference = "",
                AnalysisCode = "",
                CompanyOutletGUID = Guid.NewGuid(),
                CompanyOutletId = 1234,
                Country = "United States",
                CustomerGUID = customerGuid,
                CustomerSiteId = 1234,
                CustomerSiteStateId = CustomerSiteStateEnum.Active,
                Email = "*****@*****.**",
                EPAId = "EPAId",
                FaxNo = "",
                GUID = customerSiteGuid,
                HouseNumber = "1234",
                LastChangeReasonId = 1,
                LocationCoordinates = new GeographyPointPartialEntity()
                {
                    GUID = Guid.NewGuid(),
                    LastChangeReasonId = 1,
                    Lat = 123.45,
                    Long = 1243.234,
                },
                LocationId = 1234,
                LocationDescription = "Something about the location",
                MobileAlertNumber = "555-555-5555",
                Postcode = "46617",
                SalesRep = "Sales Rep",
                SiteName = "Some Name"
                //SiteOrders = new SiteOrderPartialEntity[1]
                //{
                //    new SiteOrderPartialEntity
                //    {
                //        a
                //    }
                //}

            };

            locations.Add(customerSiteLocation
            */
            var customerServiceClient = new CustomerServiceClient();
            System.Diagnostics.Debug.Write("Created Customer Client!\n");

            var hasErrors = false;
            // guid = customerServiceClient.SaveCustomerSites(ak, locations.ToArray(), null);
            if (hasErrors == false){
                System.Diagnostics.Debug.Write("Successfully added location.\n");
            }

            var location = customerServiceClient.GetCustomerSites(AUTHKEY, 2134);

            foreach ( CustomerSiteLocationEntity l in location) {
                System.Diagnostics.Debug.Write("Customer Location:\n");
                System.Diagnostics.Debug.Write("Site Name:" + l.SiteName + "\n");
                System.Diagnostics.Debug.Write("Address1:" + l.Address1 + "\n");
                System.Diagnostics.Debug.Write("MobileAlertNumber:" + l.MobileAlertNumber + "\n");
            }

            customerServiceClient.Close();
            System.Diagnostics.Debug.Write("Successfully closed client connection.\n");
        }
Ejemplo n.º 26
0
        static void Main(string[] args)
        {
            try
            {
                var AUTHKEY = "";
                List<CustomerPartialEntity> customers = new List<CustomerPartialEntity>();
                //create new customer service data
                Guid actionGuid = new Guid("9C42C9F6-BAEF-E311-B2BF-2016D8955EB5");
                Guid dayOfWeekGuid = new Guid("43BF01F0-BAEF-E311-B2BF-2016D8955EB5");
                Guid pickupIntervalGuid = new Guid("0C44C9F6-BAEF-E311-B2BF-2016D8955EB5");

                //generate new guids for the new customer to be referenced when we create a new customer entity
                var customerGuid1 = Guid.NewGuid();
                var customerSiteGuid1 = Guid.NewGuid();
                var customerGuid2 = Guid.NewGuid();
                var customerSiteGuid2 = Guid.NewGuid();
                var siteOrderGuid = Guid.NewGuid();
                var customerSiteContainerGuid = Guid.NewGuid();
                var customerSiteRouteAssignmentGuid = Guid.NewGuid();
                System.Diagnostics.Debug.Write("PreCustomer!\n");

                //new customer instance with associated site, order, container, & route
                var customerEntity1 = new CustomerPartialEntity()
                {
                    GUID = customerGuid1,
                    CustomerName = "John Doe One",
                    CustomerId = 123456789,
                    ARAccountCode = "7654321",
                    HqLocationId = 1234,
                    CompanyId = 1, //required
                    LastChangeReasonId = 1234,
                    CustomerStateId = CustomerStateEnum.Closed,
                    //ExtensionData =
                    CustomerSites = new CustomerSiteLocationPartialEntity[1]
                    {
                             new CustomerSiteLocationPartialEntity()
                             {
                                 CustomerSiteStateId = CustomerSiteStateEnum.Closed,
                                 GUID = customerSiteGuid1,
                                 SiteName = "Home",
                                 Address1 = "1234 Test Drive, South Bend IN",
                                 TelNo = "574-123-4567",
                                 CompanyOutletId = 1234,
                                 CompanyOutletGUID = new Guid("0C44C9F6-BAEF-E311-B2BF-2016D8955EB5"),
                                 LocationId = 1234,
                                 LastChangeReasonId = 1234,
                                 ZoneId =1234/*,
                                 SiteOrders = new SiteOrderPartialEntity[1]
                                 {
                                     new SiteOrderPartialEntity()
                                     {
                                         CustomerSiteContainers = new CustomerSiteContainerPartialEntity[]
                                         {
                                             new CustomerSiteContainerPartialEntity
                                             {
                                                 ContainerTypeId = 1234,

                                             }
                                         }
                                         CompanyOutletId = 3,
                                         GUID = siteOrderGuid,
                                         ServiceId = 1234,
                                         DestinationLocationId = 1234,
                                         //ItemTimeStamp = new DateTime(),
                                         LastChangeReasonId = 1234,
                                         MaterialId = 1234,
                                         PriorityId = 1234,
                                         //ProcessFrom = new DateTime(),
                                         //ExtensionData = new System.Runtime.Serialization.ExtensionDataObject { },
                                         SiteOrderItems = new SiteOrderItemEntity[]
                                         {
                                             new SiteOrderItemEntity
                                             {
                                                 //GUID,
                                                 //ContainerTypeId,
                                                 //LastChangeReasonId,
                                                 //ContainerId,
                                                 //ExtensionData
                                                 Container = new ContainerPartialEntity()
                                                 {
                                                     ARAccountCode = "123123",
                                                     ContainerId = 1234,
                                                     CustomerSiteId = 1233,
                                                     //ExtensionData
                                                     LastChangeReasonId = 1234,
                                                     Lat = 123.4,
                                                     Long = -123.4,
                                                     Material = "material",
                                                     MaterialId = 1234,
                                                     Size = 123,
                                                     Tag = "tag"

                                                 }
                                             }
                                         }
                                     }
                                 }*/

                             }
                    }
                };
                var customerEntity2 = new CustomerPartialEntity()
                {
                    GUID = customerGuid2,
                    CustomerName = "John Doe Two",
                    CustomerId = 99999999,
                    ARAccountCode = "7654321",
                    HqLocationId = 1234,
                    CompanyId = 1, //required
                    LastChangeReasonId = 1234,
                    CustomerStateId = CustomerStateEnum.Closed,
                    //ExtensionData =
                    CustomerSites = new CustomerSiteLocationPartialEntity[1]
                   {
                             new CustomerSiteLocationPartialEntity()
                             {
                                Address1 = "Main Street",
                                Address2 = "",
                                Address3 = "4234234.4234234.234234",
                                Address4 = "South Bend",
                                Address5 = "",
                                AlternativeSearchReference = "",
                                AnalysisCode = "",
                                CompanyOutletGUID = Guid.NewGuid(),
                                CompanyOutletId = 1234,
                                Country = "United States",
                                CustomerGUID = customerGuid2,
                                CustomerSiteId = 1234,
                                CustomerSiteStateId = CustomerSiteStateEnum.Active,
                                Email = "*****@*****.**",
                                EPAId = "EPAId",
                                FaxNo = "",
                                GUID = customerSiteGuid2,
                                HouseNumber = "1234",
                                LastChangeReasonId = 1,
                                LocationCoordinates = new GeographyPointPartialEntity()
                                {
                                    GUID = Guid.NewGuid(),
                                    LastChangeReasonId = 1,
                                    Lat = 123.45,
                                    Long = 1243.234,
                                },
                                LocationId = 12345,
                                LocationDescription = "Something about the location",
                                MobileAlertNumber = "555-555-5555",
                                Postcode = "46617",
                                SalesRep = "Sales Rep",
                                SiteName = "Some Name"

                             }
                   }
                };
                customers.Add(customerEntity1);
                customers.Add(customerEntity2);
                System.Diagnostics.Debug.Write("Post Customers!\n");

                //create the client
                var customerServiceClient = new CustomerServiceClient();
                System.Diagnostics.Debug.Write("Created Customer Client!\n");
                //save the customer

                var hasErrors = false;
                //var guid = customerServiceClient.Save(AUTHKEY, customerEntity, null,hasErrors);
                var guids = customerServiceClient.SaveCustomers(AUTHKEY, customers.ToArray(), null, hasErrors);
                System.Diagnostics.Debug.Write(hasErrors + "\n");
                if (guids.Count() == customers.Count)
                {
                    System.Diagnostics.Debug.Write("Successfully created customers.\n");
                    System.Diagnostics.Debug.Write(guids.Count() + "\n");
                }

                //Added two customers, now switch their locations aka CustomerSites

                var customer1 = customerServiceClient.GetCustomerByGuid(AUTHKEY, customerGuid1);
                var customer2 = customerServiceClient.GetCustomerByGuid(AUTHKEY, customerGuid2);
                System.Diagnostics.Debug.Write("Retrieved Customers!\n");

                //Swap CustomerSites
                var tempCustomerSites = customer1.CustomerSites;
                customer1.CustomerSites = customer2.CustomerSites;
                customer2.CustomerSites = tempCustomerSites;

                List<CustomerPartialEntity> updatedCustomers = new List<CustomerPartialEntity>();
                updatedCustomers.Add(customer1);
                updatedCustomers.Add(customer2);

                //Save Updated Customers
                guids = customerServiceClient.SaveCustomers(AUTHKEY, updatedCustomers.ToArray(), null, hasErrors);
                System.Diagnostics.Debug.Write(hasErrors + "\n");
                if (guids.Count() == customers.Count)
                {
                    System.Diagnostics.Debug.Write("Successfully updated customers.\n");
                    System.Diagnostics.Debug.Write(guids.Count() + "\n");
                }

                //Close the customer
                customerServiceClient.Close();
                System.Diagnostics.Debug.Write("Successfully closed client connection.\n");

                //Start Update
                //customerServiceClient = new CustomerServiceClient();

            }
            catch (FaultException ex)
            {
                System.Diagnostics.Debug.Write(string.Format("Failed to insert and update customer. - {0}", ex.Message));
            }
        }
Ejemplo n.º 27
0
 void MainPage_Loaded(object sender, RoutedEventArgs e)
 {
     var proxy = new CustomerServiceClient();
     proxy.GetCustomersCompleted += proxy_GetCustomersCompleted;
     proxy.GetCustomersAsync();
 }
Ejemplo n.º 28
0
        private void btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            //use the loaded customer object to preserve data signature:
            Customer customer = this.CurrentCustomer;
            //update fields:
            customer.Id = int.Parse(this.txtId.Text);
            customer.Name = this.txtName.Text;
            customer.StartDate = Convert.ToDateTime(this.txtStartDate.Text);
            customer.CreditLimit = Convert.ToSingle(this.txtCreditLimit.Text);
            BitmapImage image = this.imgLogo.Source as BitmapImage;
            customer.Logo = BufferFromImage(image);

            using (CustomerServiceClient serviceClient = new CustomerServiceClient())
            {
                serviceClient.Open();
                try
                {
                    serviceClient.UpdateCustomer(customer);
                    MessageBox.Show("Changes saved");
                    //reload:
                    this.btnLoad_Click(null, null);
                }
                catch (FaultException<NoDataSignature> noSignatureException)
                {
                    MessageBox.Show("Data signature not found. Changes not saved", "Concurrency Violation");
                }
                catch (FaultException<ConcurrencyViolation> concurrencyViolationException)
                {
                    MessageBox.Show("Record has been updated by another user. Changes not saved", "Concurrency Violation");
                }
                serviceClient.Close();
            }
        }
 public static CustomerServiceClient CreateCustomerServiceClient(this CommerceClients source, string serviceUrl)
 {
     var client = new CustomerServiceClient(new Uri(serviceUrl), source.CreateMessageProcessingHandler());
     return client;
 }
 public static CustomerServiceClient CreateCustomerServiceClient(this CommerceClients source, string serviceUrl, string appId, string secretKey)
 {
     var client = new CustomerServiceClient(new Uri(serviceUrl), appId, secretKey);
     return client;
 }