Beispiel #1
0
        public IEnumerable <IResult> DeleteTransaction(PostingRecord transactionRecord)
        {
            var openConfirmationResult = new OpenConfirmationResult(eventAggregator)
            {
                Message =
                    string.Format(Resources.Strings.PostingViewModelBase_DeleteConfirmation_Message, transactionRecord.TransactionId),
                Title   = Resources.Strings.PostingViewModelBase_DeleteConfirmation_Title,
                Options = MessageBoxOptions.Yes | MessageBoxOptions.Cancel,
            };

            yield return(openConfirmationResult);

            if (openConfirmationResult.Selected == MessageBoxOptions.Yes)
            {
                // Load transaction from server (used below to determine if the deleted posting was transfer)
                var request = new GetPostingResult(AccountId, transactionRecord.TransactionId, eventAggregator);
                yield return(request);

                // Remove transaction on server
                var request2 = new DeleteTransactionResult(AccountId,
                                                           transactionRecord.TransactionId);
                yield return(request2);

                // Update accounts balance
                accountsRepository.Download(AccountId);

                // Update category usage
                if (transactionRecord.Category != null)
                {
                    categoriesRepository.Download(transactionRecord.Category.Id);
                }

                // For transfer the 2-nd account should also be updated
                if (request.Transaction is TransferDTO)
                {
                    int secondAccountId = ((TransferDTO)request.Transaction).SecondAccountId.Value;
                    accountsRepository.Download(secondAccountId);
                }

                // Remove transaction locally
                var transactionToDelete =
                    TransactionRecords.Where(record => record.TransactionId == transactionRecord.TransactionId).Single();
                var index = TransactionRecords.IndexOf(transactionToDelete);
                TransactionRecords.Remove(transactionToDelete);

                // Correct remained balance for following transactions
                if (TransactionRecords.Count > 0 && index < TransactionRecords.Count)
                {
                    var deletedAmount = transactionToDelete.Income > 0
                                                                ? -transactionToDelete.Income
                                                                : transactionToDelete.Expense;

                    for (int i = index; i < TransactionRecords.Count; i++)
                    {
                        ((PostingRecord)TransactionRecords[i]).Balance += deletedAmount;
                    }
                }
            }
        }
Beispiel #2
0
        public IEnumerable <IResult> EditPosting(PostingRecord transactionRecord)
        {
            if (transactionRecord.Journal is TransactionDTO)
            {
                TransactionDetails.Edit(transactionRecord.Journal as TransactionDTO, AccountId);
                ActivateItem(TransactionDetails);
            }
            else if (transactionRecord.Journal is TransferDTO)
            {
                var transferResult = new GetPostingResult(AccountId, transactionRecord.TransactionId, eventAggregator);
                yield return(transferResult);

                var transfer = transferResult.Transaction as TransferDTO;
                TransferDetails.Edit(transfer, AccountId);
                ActivateItem(TransferDetails);
            }
            else
            {
                throw new NotSupportedException(string.Format("Transaction of type {0} is not editable.", transactionRecord.Journal.GetType()));
            }
        }
Beispiel #3
0
 public AddTransactionRecordBaseResult(JournalDTO journal, ICategoriesRepository repository)
 {
     Journal = journal;
     categoriesRepository = repository;
     TransactionRecord    = new PostingRecord();
 }