public void GetFirstCustomer()
        {
            try
            {
                MainModuleServiceClient client = new MainModuleServiceClient();

                client.GetPagedCustomerAsync(new PagedCriteria()
                {
                    PageIndex = 0, PageCount = 10
                });

                client.GetPagedCustomerCompleted += delegate(object sender, GetPagedCustomerCompletedEventArgs e)
                {
                    Customer[] listCustomers = e.Result;
                    if (listCustomers != null && listCustomers.Length > 0)
                    {
                        Customer = listCustomers[0];
                        GetCustomerOrders();
                    }
                };
            }
            catch (Exception excep)
            {
                Debug.WriteLine("GetFirstCustomer: Error at Service:" + excep.ToString());
            }
        }
        public void SearchCustomers(string name)
        {
            try
            {
                MainModuleServiceClient client = new MainModuleServiceClient();

                client.GetPagedCustomerCompleted += delegate(object sender, GetPagedCustomerCompletedEventArgs e)
                {
                    Customer[] listCustomers = e.Result;
                    if (listCustomers != null && listCustomers.Length > 0)
                    {
                        var resultOrders = from o in listCustomers
                                           where o.ContactName.ToLower().Contains(name.ToLower())
                                           select o;
                        Customers.Clear();
                        foreach (var item in resultOrders)
                        {
                            Customers.Add(item);
                        }
                    }
                };

                client.GetPagedCustomerAsync(new PagedCriteria()
                {
                    PageIndex = this.CurrentPage, PageCount = 4
                });
            }
            catch (Exception excep)
            {
                Debug.WriteLine("SearchCustomers: Error at Service:" + excep.ToString());
            }
        }
        private void SaveExecute()
        {
            try
            {
                Customer customer = null;
                if (ContactName != null)
                {
                    if (!string.IsNullOrEmpty(this.ContactName.Trim()))
                    {
                        MainModuleServiceClient client = new MainModuleServiceClient();

                        client.GetPagedCustomerAsync(new PagedCriteria()
                        {
                            PageIndex = 0, PageCount = 100
                        });

                        client.GetPagedCustomerCompleted += delegate(object s, GetPagedCustomerCompletedEventArgs e)
                        {
                            List <Customer> customers = new List <Customer>();
                            foreach (var item in e.Result)
                            {
                                customers.Add(item);
                            }

                            if (customers != null)
                            {
                                Order.Customer = (from c in customers where c.ContactName.Equals(this.ContactName.Trim(), StringComparison.InvariantCultureIgnoreCase) select c).FirstOrDefault <Customer>();
                            }
                            else
                            {
                                this.ContactName = string.Empty;
                            }

                            if (this.Order.Customer != null)
                            {
                                this.Order.ChangeTracker.State = ObjectState.Added;

                                client.AddOrderAsync(this.Order);
                                this._currentOrder = new Order();
                                this.Order         = new Order();
                            }
                        };
                    }
                }
            }
            catch (FaultException <ServiceError> ex)
            {
                MessageBox.Show(ex.Detail.ErrorMessage);
            }
        }
        private Customer GetCustomerByName()
        {
            Customer customer = null;

            if (ContactName != null)
            {
                if (!string.IsNullOrEmpty(this.ContactName.Trim()))
                {
                    MainModuleServiceClient client = new MainModuleServiceClient();

                    client.GetPagedCustomerAsync(new PagedCriteria()
                    {
                        PageIndex = 0, PageCount = 100
                    });

                    client.GetPagedCustomerCompleted += delegate(object s, GetPagedCustomerCompletedEventArgs e)
                    {
                        List <Customer> customers = new List <Customer>();
                        foreach (var item in e.Result)
                        {
                            customers.Add(item);
                        }

                        if (customers != null)
                        {
                            customer = (from c in customers where c.ContactName.Equals(this.ContactName.Trim(), StringComparison.InvariantCultureIgnoreCase) select c).FirstOrDefault <Customer>();
                        }
                        else
                        {
                            this.ContactName = string.Empty;
                        }
                    };
                }
            }
            return(customer);
        }
        public void GetCustomers()
        {
            try
            {
                MainModuleServiceClient client = new MainModuleServiceClient();

                client.GetPagedCustomerCompleted += delegate(object sender, GetPagedCustomerCompletedEventArgs e)
                {
                    Customer[] listCustomers = e.Result;
                    if (listCustomers != null && listCustomers.Length > 0)
                    {
                        Customers.Clear();
                        foreach (var item in listCustomers)
                        {
                            Customers.Add(item);
                        }
                    }
                    if (listCustomers.Length < 4 || listCustomers.Length == 0)
                    {
                        if (this.CurrentPage > 1)
                        {
                            this.CurrentPage--;
                        }
                    }
                };

                client.GetPagedCustomerAsync(new PagedCriteria()
                {
                    PageIndex = this.CurrentPage, PageCount = 4
                });
            }
            catch (Exception excep)
            {
                Debug.WriteLine("GetCustomers: Error at Service:" + excep.ToString());
            }
        }
        public void GetFirstCustomer()
        {
            try
            {
                MainModuleServiceClient client = new MainModuleServiceClient();

                client.GetPagedCustomerAsync(new PagedCriteria() { PageIndex = 0, PageCount = 10 });

                client.GetPagedCustomerCompleted += delegate(object sender, GetPagedCustomerCompletedEventArgs e)
                {
                    Customer[] listCustomers = e.Result;
                    if (listCustomers != null && listCustomers.Length > 0)
                    {
                        Customer = listCustomers[0];
                        GetCustomerOrders();
                    }
                };
            }
            catch (Exception excep)
            {
                Debug.WriteLine("GetFirstCustomer: Error at Service:" + excep.ToString());
            }
        }
        public void SearchCustomers(string name)
        {
            try
            {
                MainModuleServiceClient client = new MainModuleServiceClient();

                client.GetPagedCustomerCompleted += delegate(object sender, GetPagedCustomerCompletedEventArgs e)
                {
                    Customer[] listCustomers = e.Result;
                    if (listCustomers != null && listCustomers.Length > 0)
                    {
                        var resultOrders = from o in listCustomers
                                           where o.ContactName.ToLower().Contains(name.ToLower())
                                           select o;
                        Customers.Clear();
                        foreach (var item in resultOrders)
                        {
                            Customers.Add(item);
                        }

                    }
                };

                client.GetPagedCustomerAsync(new PagedCriteria() { PageIndex = this.CurrentPage, PageCount = 4 });
            }
            catch (Exception excep)
            {
                Debug.WriteLine("SearchCustomers: Error at Service:" + excep.ToString());
            }
        }
        public void GetCustomers()
        {
            try
            {
                MainModuleServiceClient client = new MainModuleServiceClient();

                client.GetPagedCustomerCompleted += delegate(object sender, GetPagedCustomerCompletedEventArgs e)
                {
                    Customer[] listCustomers = e.Result;
                    if (listCustomers != null && listCustomers.Length > 0)
                    {
                        Customers.Clear();
                        foreach (var item in listCustomers)
                        {
                            Customers.Add(item);
                        }
                    }
                    if (listCustomers.Length < 4 || listCustomers.Length == 0)
                    {
                        if (this.CurrentPage > 1)
                        {
                            this.CurrentPage--;
                        }
                    }
                };

                client.GetPagedCustomerAsync(new PagedCriteria() { PageIndex = this.CurrentPage, PageCount = 4 });
            }
            catch (Exception excep)
            {
                Debug.WriteLine("GetCustomers: Error at Service:" + excep.ToString());
            }
        }
        private Customer GetCustomerByName()
        {

            Customer customer = null;
            if (ContactName != null)
                if (!string.IsNullOrEmpty(this.ContactName.Trim()))
                {
                    MainModuleServiceClient client = new MainModuleServiceClient();

                    client.GetPagedCustomerAsync(new PagedCriteria() { PageIndex = 0, PageCount = 100 });

                    client.GetPagedCustomerCompleted += delegate(object s, GetPagedCustomerCompletedEventArgs e)
                    {

                        List<Customer> customers = new List<Customer>();
                        foreach (var item in e.Result)
                        {
                            customers.Add(item);
                        }

                        if (customers != null)
                        {
                            customer = (from c in customers where c.ContactName.Equals(this.ContactName.Trim(), StringComparison.InvariantCultureIgnoreCase) select c).FirstOrDefault<Customer>();
                        }
                        else
                            this.ContactName = string.Empty;
                    };

                }
            return customer;
        }
        private void SaveExecute()
        {
            try
            {
                Customer customer = null;
                if (ContactName != null)
                    if (!string.IsNullOrEmpty(this.ContactName.Trim()))
                    {
                        MainModuleServiceClient client = new MainModuleServiceClient();

                        client.GetPagedCustomerAsync(new PagedCriteria() { PageIndex = 0, PageCount = 100 });

                        client.GetPagedCustomerCompleted += delegate(object s, GetPagedCustomerCompletedEventArgs e)
                        {

                            List<Customer> customers = new List<Customer>();
                            foreach (var item in e.Result)
                            {
                                customers.Add(item);
                            }

                            if (customers != null)
                            {
                                Order.Customer = (from c in customers where c.ContactName.Equals(this.ContactName.Trim(), StringComparison.InvariantCultureIgnoreCase) select c).FirstOrDefault<Customer>();
                            }
                            else
                                this.ContactName = string.Empty;

                            if (this.Order.Customer != null)
                            {
                                this.Order.ChangeTracker.State = ObjectState.Added;

                                client.AddOrderAsync(this.Order);
                                this._currentOrder = new Order();
                                this.Order = new Order();
                            }
                        };

                    }

               
            }
            catch (FaultException<ServiceError> ex)
            {
                MessageBox.Show(ex.Detail.ErrorMessage);
            }
        }