public IncomeCardResult(FinanceStatementCollection incomes) { Content = incomes.GetFinanceStatements().Select(income => { return(new FinanceStatementQueryResult(income.Id, income.Title, 0, income.AmountRecords)); }); }
private AccountBuilder() { Id = Guid.NewGuid(); Actived = true; Incomes = new FinanceStatementCollection(); Expenses = new FinanceStatementCollection(); Investments = new FinanceStatementCollection(); }
public AccountBuilder WithExpenses(params decimal[] values) { var list = new List <Expense>(); foreach (var value in values) { list.Add(Expense.Load(Guid.NewGuid(), GenerateName(9), new AmountRecordCollection(new[] { AmountRecord.Load(Guid.NewGuid(), null, value) }), MonthYear.Now)); } Expenses = new FinanceStatementCollection(list); return(this); }
public AccountBuilder WithExpenses(int length = 2) { var list = new List <Expense>(); for (int i = 0; i < length; i++) { list.Add(Expense.Load(Guid.NewGuid(), GenerateName(9), new AmountRecordCollection(new[] { AmountRecord.Load(Guid.NewGuid(), null, GenerateDecimal()) }), MonthYear.Now)); } Expenses = new FinanceStatementCollection(list); return(this); }
public AccountQueryResult(System.Guid accountId, FinanceStatementCollection expenses, FinanceStatementCollection incomes, FinanceStatementCollection investments) { decimal totalIncomes = incomes.Total(); AccountId = accountId; CurrentBalance = totalIncomes - expenses.Total() + investments.Total(); Incomes = new IncomeCardResult(incomes); Expenses = new ExpenseCardResult(expenses, totalIncomes); Investments = new InvestmentCardResult(investments, totalIncomes); }
public InvestmentCardResult(FinanceStatementCollection investments, decimal totalIncome) { decimal total = investments.Total(); double percent = investments.Percentage(totalIncome); Total = new TotalQueryResult(total, percent); Content = investments.GetFinanceStatements().Select(investment => { return(new FinanceStatementQueryResult(investment.Id, investment.Title, total, investment.AmountRecords)); }); }
public ExpenseCardResult(FinanceStatementCollection expenses, decimal totalIncome) { decimal total = expenses.Total(); double percent = expenses.Percentage(totalIncome); Total = new TotalQueryResult(total, percent); Content = expenses.GetFinanceStatements().Select(expense => { return(new FinanceStatementQueryResult(expense.Id, expense.Title, total, expense.AmountRecords)); }); }
public AccountBuilder WithInvestments(Guid firstItemId, int length = 3) { var list = new List <Investment>(); list.Add(Investment.Load(firstItemId, GenerateName(9), new AmountRecordCollection(new[] { AmountRecord.Load(Guid.NewGuid(), null, GenerateDecimal()) }), MonthYear.Now)); for (int i = 0; i < length - 1; i++) { list.Add(Investment.Load(Guid.NewGuid(), GenerateName(9), new AmountRecordCollection(new[] { AmountRecord.Load(Guid.NewGuid(), null, GenerateDecimal()) }), MonthYear.Now)); } Investments = new FinanceStatementCollection(list); return(this); }
public async Task <CreateFinanceStatementResult> Execute <T>(Guid accountId, Title title, Amount amount = null) where T : class, IFinanceStatement { Account account = await _accountReadOnlyRepository.Get(accountId); if (account == null) { throw new AccountNotFoundException($"The account {accountId} does not exists!"); } T financeStatement = (T)Activator.CreateInstance(typeof(T), title, amount); FinanceStatementCollection collection = account .GetCollecion <T>(); collection.Add(financeStatement); await _accountWriteOnlyRepository.Update(account, financeStatement); decimal totalIncomes = account.Incomes.Total(); decimal totalExpenses = account.Expenses.Total(); decimal totalInvestments = account.Investments.Total(); CreateFinanceStatementResult result = new CreateFinanceStatementResult { Id = financeStatement.Id, Total = financeStatement.AmountRecords.Total(), Percentage = financeStatement.AmountRecords.Percentage(collection.Total()), AmountRecords = financeStatement.AmountRecords.GetAmountRecords().Select(x => new Results.AmountRecordResult { Id = x.Id, Amount = x.Amount, Description = x.Description }), 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); }
public AccountBuilder WithIncomes(Guid firstItemId, params decimal[] values) { var list = new List <Income>(); list.Add(Income.Load(firstItemId, GenerateName(9), new AmountRecordCollection(new[] { AmountRecord.Load(Guid.NewGuid(), null, values[0]) }), MonthYear.Now)); for (int i = 1; i < values.Length; i++) { list.Add(Income.Load(Guid.NewGuid(), GenerateName(9), new AmountRecordCollection(new[] { AmountRecord.Load(Guid.NewGuid(), null, values[i]) }), MonthYear.Now)); } Incomes = new FinanceStatementCollection(list); return(this); }
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); }
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); }
public async Task <AccountQueryResult> GetAccount(System.Guid accountId) { Entities.Account account = await _context .Accounts .Find(x => x.Id == accountId) .SingleOrDefaultAsync(); if (account == null) { throw new AccountNotFoundException($"The account {accountId} does not exists"); } if (!account.Actived) { throw new AccountDeactivatedException($"The account {accountId} is deactivated!"); } IEnumerable <Entities.FinanceStatement> incomes = await _context .Incomes .Find(x => x.AccountId == accountId) .ToListAsync(); IEnumerable <Entities.FinanceStatement> expenses = await _context .Expenses .Find(x => x.AccountId == accountId) .ToListAsync(); IEnumerable <Entities.FinanceStatement> investments = await _context .Investments .Find(x => x.AccountId == accountId) .ToListAsync(); FinanceStatementCollection incomeCollection = new FinanceStatementCollection(); foreach (var income in incomes) { IEnumerable <Entities.AmountRecord> amountRecords = await _context .AmountRecords .Find(x => x.FinanceStatementId == income.Id) .ToListAsync(); AmountRecordCollection amountRecordCollection = new AmountRecordCollection(amountRecords.Select(x => AmountRecord.Load(x.Id, x.Description, x.Amount))); incomeCollection.Add(Income.Load(income.Id, income.Title, amountRecordCollection, income.ReferenceDate)); } FinanceStatementCollection expenseCollection = new FinanceStatementCollection(); foreach (var expense in expenses) { IEnumerable <Entities.AmountRecord> amountRecords = await _context .AmountRecords .Find(x => x.FinanceStatementId == expense.Id) .ToListAsync(); AmountRecordCollection amountRecordCollection = new AmountRecordCollection(amountRecords.Select(x => AmountRecord.Load(x.Id, x.Description, x.Amount))); expenseCollection.Add(Expense.Load(expense.Id, expense.Title, amountRecordCollection, expense.ReferenceDate)); } FinanceStatementCollection investmentsCollection = new FinanceStatementCollection(); foreach (var investment in investments) { IEnumerable <Entities.AmountRecord> amountRecords = await _context .AmountRecords .Find(x => x.FinanceStatementId == investment.Id) .ToListAsync(); AmountRecordCollection amountRecordCollection = new AmountRecordCollection(amountRecords.Select(x => AmountRecord.Load(x.Id, x.Description, x.Amount))); investmentsCollection.Add(Investment.Load(investment.Id, investment.Title, amountRecordCollection, investment.ReferenceDate)); } AccountQueryResult result = new AccountQueryResult(account.Id, expenseCollection, incomeCollection, investmentsCollection); return(result); }
public async Task <Account> Get(Guid accountId) { Entities.Account account = await _context .Accounts .Find(x => x.Id == accountId) .SingleOrDefaultAsync(); IEnumerable <Entities.FinanceStatement> incomes = await _context .Incomes .Find(x => x.AccountId == accountId) .ToListAsync(); IEnumerable <Entities.FinanceStatement> expenses = await _context .Expenses .Find(x => x.AccountId == accountId) .ToListAsync(); IEnumerable <Entities.FinanceStatement> investments = await _context .Investments .Find(x => x.AccountId == accountId) .ToListAsync(); FinanceStatementCollection incomeCollection = new FinanceStatementCollection(); foreach (var income in incomes) { IEnumerable <Entities.AmountRecord> amountRecords = await _context .AmountRecords .Find(x => x.FinanceStatementId == income.Id) .ToListAsync(); AmountRecordCollection amountRecordCollection = new AmountRecordCollection(amountRecords.Select(x => AmountRecord.Load(x.Id, x.Description, x.Amount))); incomeCollection.Add(Income.Load(income.Id, income.Title, amountRecordCollection, income.ReferenceDate)); } FinanceStatementCollection expenseCollection = new FinanceStatementCollection(); foreach (var expense in expenses) { IEnumerable <Entities.AmountRecord> amountRecords = await _context .AmountRecords .Find(x => x.FinanceStatementId == expense.Id) .ToListAsync(); AmountRecordCollection amountRecordCollection = new AmountRecordCollection(amountRecords.Select(x => AmountRecord.Load(x.Id, x.Description, x.Amount))); expenseCollection.Add(Expense.Load(expense.Id, expense.Title, amountRecordCollection, expense.ReferenceDate)); } FinanceStatementCollection investmentsCollection = new FinanceStatementCollection(); foreach (var investment in investments) { IEnumerable <Entities.AmountRecord> amountRecords = await _context .AmountRecords .Find(x => x.FinanceStatementId == investment.Id) .ToListAsync(); AmountRecordCollection amountRecordCollection = new AmountRecordCollection(amountRecords.Select(x => AmountRecord.Load(x.Id, x.Description, x.Amount))); investmentsCollection.Add(Investment.Load(investment.Id, investment.Title, amountRecordCollection, investment.ReferenceDate)); } Account result = Account.Load( account.Id, account.Actived, incomeCollection, expenseCollection, investmentsCollection ); return(result); }