Пример #1
0
        public AccountBuilder WithIncomes(params decimal[] values)
        {
            var list = new List <Income>();

            foreach (var value in values)
            {
                list.Add(Income.Load(Guid.NewGuid(), GenerateName(9), new AmountRecordCollection(new[] { AmountRecord.Load(Guid.NewGuid(), null, value) }), MonthYear.Now));
            }
            Incomes = new FinanceStatementCollection(list);
            return(this);
        }
Пример #2
0
        public AccountBuilder WithIncomes(int length = 2)
        {
            var list = new List <Income>();

            for (int i = 0; i < length; i++)
            {
                list.Add(Income.Load(Guid.NewGuid(), GenerateName(9), new AmountRecordCollection(new[] { AmountRecord.Load(Guid.NewGuid(), null, GenerateDecimal()) }), MonthYear.Now));
            }
            Incomes = new FinanceStatementCollection(list);
            return(this);
        }
Пример #3
0
        public AccountBuilder WithIncome(Guid incomeId, Guid firstAmountRecordId, params decimal[] amountRecordValues)
        {
            Income income = Income.Load(incomeId, GenerateName(5), new AmountRecordCollection(), MonthYear.Now);

            income.AmountRecords.Add(AmountRecord.Load(firstAmountRecordId, GenerateName(5), amountRecordValues[0]));
            for (int i = 1; i < amountRecordValues.Length; i++)
            {
                income.AmountRecords.Add(AmountRecord.Load(Guid.NewGuid(), GenerateName(5), amountRecordValues[i]));
            }
            Incomes.Add(income);
            return(this);
        }
Пример #4
0
        public void Should_Get_Income()
        {
            Guid    incomeId = Guid.NewGuid();
            Account account  = new Account();

            Income income = Income.Load(incomeId, "bonus", null, MonthYear.Now);

            account.GetCollecion <Income>().Add(income);

            var result = account.Get <Income>(x => x.Id == incomeId);

            Assert.Equal(income, result);
            Assert.IsType <Income>(result);
        }
Пример #5
0
        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);
        }
Пример #6
0
        private void FindTransactions(DateTime startDate, DateTime endDate)
        {
            var result = this.GetTransactionsByDates(startDate, endDate, "Income");

            var transactions = new List <string>();

            foreach (object record in result)
            {
                Dictionary <string, object> temp = (Dictionary <string, object>)record;
                transactions.Add(temp["NB_FAKTUR"].ToString());
            }

            transactions = transactions.Distinct().ToList();
            foreach (string trans in transactions)
            {
                var income = new Income(this.dbAccess);
                income.Load(trans);
                this.AddTransaction(income);
            }

            result       = this.GetTransactionsByDates(startDate, endDate, "Expense");
            transactions = new List <string>();
            foreach (object record in result)
            {
                Dictionary <string, object> temp = (Dictionary <string, object>)record;
                transactions.Add(temp["NB_FAKTUR"].ToString());
            }

            transactions = transactions.Distinct().ToList();
            foreach (string trans in transactions)
            {
                var expense = new Expense(this.dbAccess);
                expense.Load(trans);
                this.AddTransaction(expense);
            }
        }
Пример #7
0
        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);
        }
Пример #8
0
        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);
        }