示例#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));
        }
示例#2
0
        private void ExcludeTimeEntry(TimeEntryListItemViewModel timeEntry)
        {
            if (timeEntry.TimeEntry.IsStopped)
            {
                return;
            }

            _dataService.ExcludeTimeEntry(timeEntry.TimeEntry);

            TimeEntries.Remove(timeEntry);
            InternalCommands.GenerateInvoiceLines.Execute(null);
            //_invoiceService.RecalculateInvoice(SelectedInvoice.Invoice);
        }
示例#3
0
        public virtual void RemoveTimeEntry(int timeEntryId)
        {
            var timeEntry = TimeEntries.Single(te => te.Id == timeEntryId);

            if (timeEntry == null)
            {
                throw new EntityDeleteException("Timeentry not found in task: " + timeEntryId);
            }

            if (timeEntry.Invoice != null)
            {
                throw new EntityDeleteException("Timeentry cannot be deleted when billed: Id:" + timeEntry.Id);
            }

            TimeEntries.Remove(timeEntry);
        }
示例#4
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));
        }