Пример #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;
                    }
                }
            }
        }
Пример #2
0
        public IEnumerable <IResult> Save()
        {
            if (IsEditMode)
            {
                // To not update date if it was not changed;
                // Add time of day to updated date only.
                var date = OperationDate.Kind == DateTimeKind.Unspecified
                                                        ? DateTime.SpecifyKind(OperationDate, DateTimeKind.Local) + DateTime.Now.TimeOfDay
                                                        : OperationDate;

                var request = new UpdateTransferResult(
                    transactionId.Value,
                    ((AccountDTO)SourceAccounts.CurrentItem).Id,
                    ((AccountDTO)TargetAccounts.CurrentItem).Id,
                    date.ToUniversalTime(),
                    decimal.Parse(Amount.Trim()),
                    Comment != null ? Comment.Trim() : null,
                    eventAggregator
                    );

                yield return(request);
            }
            else
            {
                // Add time of day to date.
                var date = OperationDate.Kind == DateTimeKind.Unspecified
                                                        ? DateTime.SpecifyKind(OperationDate, DateTimeKind.Local) + DateTime.Now.TimeOfDay
                                                        : OperationDate.Date + DateTime.Now.TimeOfDay;

                var request = new AddTransferResult(((AccountDTO)SourceAccounts.CurrentItem).Id,
                                                    ((AccountDTO)TargetAccounts.CurrentItem).Id,
                                                    date.ToUniversalTime(),
                                                    decimal.Parse(Amount.Trim()),
                                                    Comment != null ? Comment.Trim() : null,
                                                    eventAggregator
                                                    );

                yield return(request);
            }

            var sourceAccountId = (AccountDTO)SourceAccounts.CurrentItem;
            var targetAccountId = (AccountDTO)TargetAccounts.CurrentItem;

            var accountsToUpdate = new[]
            {
                prevSourceAccont.Id,
                prevTargetAccont.Id,
                sourceAccountId.Id,
                targetAccountId.Id,
            }
            .Distinct();

            // Download only updated accounts (up to 4 in worst case)
            foreach (var accountId in accountsToUpdate)
            {
                accountsRepository.Download(accountId);
            }

            Cancel();
        }
Пример #3
0
        public IEnumerable <IResult> Save()
        {
            if (IsEditMode)
            {
                // To not update date if it was not changed;
                // Add time of day to updated date only.
                DateTime date = OperationDate.Kind == DateTimeKind.Unspecified
                                                        ? DateTime.SpecifyKind(OperationDate, DateTimeKind.Local) + DateTime.Now.TimeOfDay
                                                        : OperationDate;

                var request = new EditTransactionResult(
                    transactionId.Value,
                    AccountId,
                    date.ToUniversalTime(),
                    decimal.Parse(Price.Trim()),
                    decimal.Parse(Quantity.Trim()),
                    Comment != null ? Comment.Trim() : null,
                    CurrentCategory != null
                                                ? CurrentCategory.Id
                                                : (int?)null,
                    IsDeposite,
                    eventAggregator
                    );


                yield return(request);
            }
            else
            {
                // Add time of day to date.
                DateTime date = OperationDate.Kind == DateTimeKind.Unspecified
                                                        ? DateTime.SpecifyKind(OperationDate, DateTimeKind.Local) + DateTime.Now.TimeOfDay
                                                        : OperationDate.Date + DateTime.Now.TimeOfDay;

                var request = new AddTransactionResult(AccountId,
                                                       date.ToUniversalTime(),
                                                       decimal.Parse(Price.Trim()),
                                                       decimal.Parse(Quantity.Trim()),
                                                       Comment != null ? Comment.Trim() : null,
                                                       CurrentCategory != null
                                                ? CurrentCategory.Id
                                                : (int?)null,
                                                       IsDeposite,
                                                       eventAggregator
                                                       );

                yield return(request);
            }

            accountsRepository.Download(AccountId);

            if (CurrentCategory != null)
            {
                categoryRepository.Download(CurrentCategory.Id);
            }

            if (previousCategory != null && CurrentCategory != null && CurrentCategory.Id != previousCategory.Id)
            {
                categoryRepository.Download(previousCategory.Id);
            }

            Cancel();
        }