Exemplo n.º 1
0
        private void onTimeEntryDeleted(long id)
        {
            var viewModel = TimeEntries.Select(c => c.SingleOrDefault(vm => vm.Id == id)).SingleOrDefault(vm => vm != null);

            if (viewModel == null)
            {
                return;
            }

            var collection = TimeEntries.SingleOrDefault(c => c.Date == viewModel.Start.Date);

            if (collection == null)
            {
                return;
            }

            collection.Remove(viewModel);
            var indexToInsert = TimeEntries.IndexOf(collection);

            TimeEntries.Remove(collection);

            if (collection.Count > 0)
            {
                var newCollection = new TimeEntryViewModelCollection(collection.Date.DateTime, collection);
                TimeEntries.Insert(indexToInsert, newCollection);
            }

            RaisePropertyChanged(nameof(IsEmpty));
        }
Exemplo n.º 2
0
        private void insertNewTimeEntryGroup(IThreadSafeTimeEntry timeEntry, DateTime indexDate)
        {
            var timeEntryToAdd = new TimeEntryViewModel(timeEntry, durationFormat);
            var newCollection  = new TimeEntryViewModelCollection(indexDate, new[] { timeEntryToAdd }, durationFormat);
            var foundIndex     = TimeEntries.IndexOf(TimeEntries.FirstOrDefault(x => x.Date < indexDate));
            var indexToInsert  = foundIndex == -1 ? TimeEntries.Count : foundIndex;

            TimeEntries.Insert(indexToInsert, newCollection);
        }
Exemplo n.º 3
0
        private void onTimeEntryCreated(IDatabaseTimeEntry timeEntry)
        {
            var indexDate        = timeEntry.Start.Date;
            var timeEntriesInDay = new List <TimeEntryViewModel> {
                new TimeEntryViewModel(timeEntry)
            };

            var collection = TimeEntries.FirstOrDefault(x => x.Date == indexDate);

            if (collection != null)
            {
                timeEntriesInDay.AddRange(collection);
                TimeEntries.Remove(collection);
            }

            var newCollection = new TimeEntryViewModelCollection(indexDate, timeEntriesInDay.OrderByDescending(te => te.Start));

            var foundIndex    = TimeEntries.IndexOf(TimeEntries.FirstOrDefault(x => x.Date < indexDate));
            var indexToInsert = foundIndex == -1 ? TimeEntries.Count : foundIndex;

            TimeEntries.Insert(indexToInsert, newCollection);

            RaisePropertyChanged(nameof(IsEmpty));
        }