Beispiel #1
0
        public async Task <RemoveFinanceStatementResult> Execute <T>(Guid accountId, Guid financeStatementId) where T : class, IFinanceStatement
        {
            Account account = await _accountReadOnlyRepository.Get(accountId);

            if (account == null)
            {
                throw new AccountNotFoundException($"The account {accountId} does not exists");
            }

            FinanceStatementCollection collection = account.GetCollecion <T>();

            T financeStatement = (T)collection.Get(financeStatementId);

            collection.Remove(financeStatement);

            await _accountWriteOnlyRepository.Remove(account, financeStatement);

            decimal totalIncomes     = account.Incomes.Total();
            decimal totalExpenses    = account.Expenses.Total();
            decimal totalInvestments = account.Investments.Total();

            RemoveFinanceStatementResult result = new RemoveFinanceStatementResult
            {
                Income = new Results.FinanceStatementResult
                {
                    Total = totalIncomes
                },
                Expense = new Results.FinanceStatementResult
                {
                    Total      = totalExpenses,
                    Percentage = account.Expenses.Percentage(totalIncomes)
                },
                Investment = new Results.FinanceStatementResult
                {
                    Total      = totalInvestments,
                    Percentage = account.Investments.Percentage(totalIncomes)
                },
            };

            return(result);
        }
Beispiel #2
0
        public async Task Execute <T>(Guid accountId, Guid financeStatementId, Title title) where T :  class, IFinanceStatement
        {
            Account account = await _accountReadOnlyRepository.Get(accountId);

            if (account == null)
            {
                throw new AccountNotFoundException($"The account {accountId} does not exists");
            }

            FinanceStatementCollection collection = account.GetCollecion <T>();

            if (collection.Any(x => x.Title == title && x.Id != financeStatementId))
            {
                throw new FinanceStatementAlreadyExistsException($"Title {title} already exists!");
            }


            FinanceStatement financeStatement = (FinanceStatement)collection.Get(financeStatementId);

            financeStatement.Update(title);

            await _accountWriteOnlyRepository.Update(account, financeStatement);
        }