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

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

            List <Package> ServerPackages = serviceHandler.CallService <List <Package> >(@"QueryPackagesWithChocolatesAndIngredients");

            if (ServerPackages != null)
            {
                List <Package> newPackages = ServerPackages.Where(i => i.Modified > LastUpdate).Select(j => j).ToList();

                foreach (var item in newPackages)
                {
                    if (dataHandler.QueryPackagesWithChocolatesAndIngredients().Where(p => p.PackageId.Equals(item.PackageId)).Count() == 0)
                    {
                        if (dataHandler.InsertPackage(item))
                        {
                            PackageInformer.Invoke();
                        }
                    }
                    else
                    {
                        if (dataHandler.UpdatePackage(item))
                        {
                            PackageInformer.Invoke();
                        }
                    }
                }
            }
        }