Example #1
0
        private void SynchronizeCustomers()
        {
            LastUpdate = new DateTime(1983, 11, 20);

            if (dataHandler.QueryCustomers().Count > 0)
            {
                LastUpdate = dataHandler.QueryCustomers().OrderByDescending(i => i.Modified).Select(j => j.Modified.GetValueOrDefault()).First();
            }

            List <Customer> ServerCustomers = serviceHandler.CallService <List <Customer> >(@"QueryCustomers");

            if (ServerCustomers != null)
            {
                List <Customer> newCustomers = ServerCustomers.Where(i => i.Modified > LastUpdate).Select(j => j).ToList();

                foreach (var item in newCustomers)
                {
                    if (dataHandler.QueryCustomers().Where(p => p.CustomerId.Equals(item.CustomerId)).Count() == 0)
                    {
                        dataHandler.InsertCustomer(item);
                    }
                    else
                    {
                        dataHandler.UpdateCustomer(item);
                    }
                }
            }
            ;
        }