public ITimeEntryHolder UpdateOrDelete (TimeEntryData data, out bool isAffectedByDelete)
        {
            isAffectedByDelete = Group.Any (x => x.Id == data.Id);

            if (isAffectedByDelete) {
                if (Group.Count == 1) {
                    return null; // Delete
                } else {
                    var updated = new TimeEntryGroup ();
                    updated.Group = Group.Where (x => x.Id != data.Id).ToList ();
                    updated.Info = updated.Data.Id == Data.Id ? Info : null; // Recycle entry info if possible
                    return updated;
                }
            } else {
                return null;
            }
        }
 public void Remove (TimeEntryGroup entryGroup)
 {
     entryGroup.Dispose();
     dataObjects.Remove (entryGroup);
 }
 public void Update (TimeEntryGroup entryGroup)
 {
     for (int i = 0; i < dataObjects.Count; i++) {
         if (dataObjects[i].Data.Matches (entryGroup.Data)) {
             dataObjects [i] = entryGroup;
         }
     }
 }
 public void Add (TimeEntryGroup entryGroup)
 {
     dataObjects.Add (entryGroup);
 }
 private int GetEntryGroupIndex (TimeEntryGroup entryGroup)
 {
     int count = 0;
     foreach (var grp in dateGroups) {
         count++;
         // Iterate by entry list.
         foreach (var obj in grp.TimeEntryGroupList) {
             if (entryGroup.Data.Matches (obj.Data)) {
                 return count;
             }
             count++;
         }
     }
     return -1;
 }
        private TimeEntryGroup GetSuitableEntryGroupFor (DateGroup dateGroup, TimeEntryData dataObject, out bool isNewEntryGroup)
        {
            isNewEntryGroup = false;

            foreach (var grp in dateGroup.TimeEntryGroupList) {
                if (grp.CanContain (dataObject)) {
                    return grp;
                }
            }

            var entryGroup = new TimeEntryGroup (dataObject);
            dateGroup.Add (entryGroup);
            isNewEntryGroup = true;

            return entryGroup;
        }
        private TimeEntryGroup GetExistingEntryGroupFor (DateGroup dateGroup, TimeEntryData dataObject, out bool isNewEntryGroup)
        {
            isNewEntryGroup = false;

            foreach (var grp in dateGroup.TimeEntryGroupList) {
                TimeEntryData entryData;
                if (grp.Contains (dataObject, out entryData)) {
                    return grp;
                }
            }

            var entryGroup = new TimeEntryGroup (dataObject);
            dateGroup.Add (entryGroup);
            isNewEntryGroup = true;

            return entryGroup;
        }
        private bool FindExistingEntry (TimeEntryData dataObject, out DateGroup dateGroup, out TimeEntryGroup existingGroup, out TimeEntryData existingEntry)
        {
            foreach (var grp in dateGroups) {
                foreach (var obj in grp.TimeEntryGroupList) {
                    TimeEntryData entry;
                    if (obj.Contains (dataObject, out entry)) {
                        dateGroup = grp;
                        existingGroup = obj;
                        existingEntry = entry;
                        return true;
                    }
                }
            }

            existingEntry = null;
            dateGroup = null;
            existingGroup = null;
            return false;
        }
        protected async override Task AddTimeEntryHolderAsync (TimeEntryHolder holder)
        {
            var entryGroup = new TimeEntryGroup (holder.TimeEntryDataList);

            bool isNewGroup;
            DateGroup grp = GetDateGroupFor (entryGroup.Data, out isNewGroup);
            grp.Add (entryGroup);
            Sort ();

            // Update Date group.
            var groupIndex = GetDateGroupIndex (grp);
            var groupAction = isNewGroup ? NotifyCollectionChangedAction.Add : NotifyCollectionChangedAction.Replace;
            await UpdateCollectionAsync (grp, groupAction, groupIndex);

            // Add time entry group.
            var newIndex = GetEntryGroupIndex (entryGroup);
            await UpdateCollectionAsync (entryGroup, NotifyCollectionChangedAction.Add, newIndex);
        }
 public GroupedEditAdapter (TimeEntryGroup entryGroup)
 {
     this.entryGroup = entryGroup;
 }