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

            if (dataHandler.QueryRatings().Count > 0)
            {
                LastUpdate = dataHandler.QueryRatings().OrderByDescending(i => i.Modified).Select(j => j.Modified.GetValueOrDefault()).First();
            }
            List <Rating> ServerRatings = serviceHandler.CallService <List <Rating> >(@"QueryRatings");

            if (ServerRatings != null)
            {
                List <Rating> newRatings = ServerRatings.Where(i => i.Modified > LastUpdate).Select(j => j).ToList();

                foreach (var item in newRatings)
                {
                    if (dataHandler.QueryRatings().Where(p => p.RatingId.Equals(item.RatingId)).Count() == 0)
                    {
                        if (dataHandler.InsertRating(item))
                        {
                            CommentsInformer.Invoke();
                        }
                    }
                    else
                    {
                        if (dataHandler.UpdateRating(item))
                        {
                            CommentsInformer.Invoke();
                        }
                    }
                }
            }
        }