private void OnAlteredElementsFound(object sender, DataSyncEventArgs <CheckIn> e)
 {
     if (e.ChangedElements.Count > 0)
     {
         foreach (var item in e.ChangedElements)
         {
             //Console.WriteLine("Yay, this works!?");
             //Console.WriteLine(item.Description);
             Console.WriteLine("Removing Element: " + item.Id);
             CheckIns.Remove(CheckIns.Single(x => x.Id == item.Id));
         }
         Updated.Invoke(this, new EventArgs());
     }
 }
        private void OnNewElementsFound(object sender, DataSyncEventArgs <CheckIn> e)
        {
            List <CheckIn> newElements = e.ChangedElements.OrderBy(x => x.AppointedTo).ToList();

            for (int i = 0; i < newElements.Count; i++)
            {
                if (newElements[i].IsAppointment && newElements[i].AppointedTo.Value.CompareTo(DateTime.Now) <= 0)
                {
                    for (int j = 0; j < i; j++)
                    {
                        if (!newElements[j].IsAppointment)
                        {
                            CheckIn temp = newElements[i];
                            newElements.RemoveAt(i);
                            newElements.Insert(j, temp);
                            break;
                        }
                    }
                }

                if (i < newElements.Count - 1 && !newElements[i].IsAppointment && newElements[i + 1].IsAppointment && newElements[i + 1].AppointedTo.Value.CompareTo(newElements[i].AppointedTo.Value) == 0)
                {
                    var temp = newElements[i];
                    newElements[i]     = newElements[i + 1];
                    newElements[i + 1] = temp;
                }
            }

            foreach (var item in newElements)
            {
                //Puts newly synchronized checkins that are earlier than the current last one in their right place.
                if (CheckIns.Count > 1 && CheckIns.Last().AppointedTo.Value.CompareTo(item.AppointedTo.Value) > 0)
                {
                    int targetIndex = CheckIns.Count - 1;
                    while (targetIndex > 1 && CheckIns[targetIndex - 1].AppointedTo.Value.CompareTo(item.AppointedTo.Value) > 0)
                    {
                        targetIndex--;
                    }
                    CheckIns.Insert(targetIndex, item);
                }
                else
                {
                    CheckIns.Add(item);
                }
            }


            Updated.Invoke(this, new EventArgs());
        }