/// <inheritdoc />
            public async Task Handle(Notification notification, CancellationToken cancellationToken)
            {
                if (notification.OldDate.Year == notification.NewDate.Year && notification.OldDate.Month == notification.NewDate.Month)
                {
                    return;
                }

                var transaction = _readDb.Transactions.FirstOrDefault(x => x.TransactionId == notification.ReferenceTransactionId);

                if (transaction == null)
                {
                    return;
                }

                await _balanceService.CalculateBudgetCategoryBalance(transaction.BudgetCategoryId,
                                                                     notification.OldDate.Year,
                                                                     notification.OldDate.Month,
                                                                     cancellationToken);

                await _balanceService.CalculateBudgetCategoryBalance(transaction.BudgetCategoryId,
                                                                     notification.NewDate.Year,
                                                                     notification.NewDate.Month,
                                                                     cancellationToken);

                _ = _mediator.Publish(new BudgetCategoryBalanceChanged.Notification()
                {
                    BudgetCategoryId = transaction.BudgetCategoryId
                }, cancellationToken);
            }
Esempio n. 2
0
            /// <inheritdoc />
            public async Task Handle(Notification notification, CancellationToken cancellationToken)
            {
                await _balanceService.CalculateBudgetCategoryBalance(notification.OldBudgetCategoryId,
                                                                     notification.ReferenceTransaction.TransactionDate.Year,
                                                                     notification.ReferenceTransaction.TransactionDate.Month,
                                                                     cancellationToken);

                await _balanceService.CalculateBudgetCategoryBalance(notification.NewBudgetCategoryId,
                                                                     notification.ReferenceTransaction.TransactionDate.Year,
                                                                     notification.ReferenceTransaction.TransactionDate.Month,
                                                                     cancellationToken);


                _ = _mediator.Publish(new BudgetCategoryBalanceChanged.Notification()
                {
                    BudgetCategoryId = notification.OldBudgetCategoryId
                }, cancellationToken);

                _ = _mediator.Publish(new BudgetCategoryBalanceChanged.Notification()
                {
                    BudgetCategoryId = notification.NewBudgetCategoryId
                }, cancellationToken);
            }
            public async Task RecalculateBalance(IEnumerable <BudgetCategory> budgetCategories, int year, int month, CancellationToken cancellationToken)
            {
                foreach (var budgetCategory in budgetCategories)
                {
                    await _balanceService.CalculateBudgetCategoryBalance(budgetCategory.BudgetCategoryId, year, month, cancellationToken);
                }

                foreach (var budgetId in budgetCategories.Select(x => x.BudgetId).Distinct())
                {
                    await _balanceService.CalculateBudgetBalance(budgetId, cancellationToken);

                    await _mediator.Publish(new BudgetBalanceChanged()
                    {
                        BudgetId = budgetId
                    }, cancellationToken);
                }
            }
Esempio n. 4
0
            /// <inheritdoc />
            public async Task Handle(Notification notification, CancellationToken cancellationToken)
            {
                var category = _readDb.BudgetCategories.FirstOrDefault(x => x.BudgetCategoryId == notification.ReferenceTransaction.BudgetCategoryId);

                if (category == null)
                {
                    return;
                }


                var dates = new List <DateTime>()
                {
                    notification.ReferenceTransaction.TransactionDate
                };

                if (notification.ReferenceTransaction.SubTransactions != null && notification.ReferenceTransaction.SubTransactions.Any())
                {
                    dates.AddRange(notification.ReferenceTransaction.SubTransactions.Select(x => x.TransactionDate));
                }

                foreach (var dateTime in dates.Select(x => x.StartOfMonth()).Distinct())
                {
                    await _balanceService.CalculateBudgetCategoryBalance(category.BudgetCategoryId,
                                                                         dateTime.Year,
                                                                         dateTime.Month,
                                                                         cancellationToken);
                }

                await _mediator.Publish(new BudgetCategoryBalanceChanged.Notification()
                {
                    BudgetCategoryId = notification.ReferenceTransaction.BudgetCategoryId
                }, cancellationToken);

                await _balanceService.CalculateBudgetBalance(category.BudgetId, cancellationToken);

                await _mediator.Publish(new BudgetBalanceChanged()
                {
                    BudgetId = category.BudgetId
                }, cancellationToken);
            }
Esempio n. 5
0
            /// <inheritdoc />
            public async Task Handle(Notification notification, CancellationToken cancellationToken)
            {
                foreach (var budgetCategory in notification.BudgetCategories)
                {
                    await _balanceService.CalculateBudgetCategoryBalance(budgetCategory.BudgetCategoryId, cancellationToken);

                    await _mediator.Publish(new BudgetCategoryBalanceChanged.Notification()
                    {
                        BudgetCategoryId = budgetCategory.BudgetCategoryId
                    }, cancellationToken);
                }


                foreach (var budgetId in notification.BudgetCategories.Select(x => x.BudgetId).Distinct())
                {
                    await _balanceService.CalculateBudgetBalance(budgetId, cancellationToken);

                    await _mediator.Publish(new BudgetBalanceChanged()
                    {
                        BudgetId = budgetId
                    }, cancellationToken);
                }
            }