예제 #1
0
        public List <AccountDetailDTO> GetUserAccounts([FromBody] String userId)
        {
            AccountDetailDTO        accountDetail;
            List <AccountDetailDTO> accountDetailList = new List <AccountDetailDTO>();

            List <BankAccount> accountsList = _accountDBAccess.FindByUser(userId);

            foreach (BankAccount account in accountsList)
            {
                List <Transaction> accountTransactions = _transactionDBAccess.FindByAccount(account.BankAccountId);

                decimal balance = _businessService.GetAccountBalance(accountTransactions, account.InitialAmount);
                accountDetail = new AccountDetailDTO
                {
                    AccountId           = account.BankAccountId,
                    Name                = account.Name,
                    InitialAmount       = account.InitialAmount,
                    Balance             = balance,
                    LastTransactionDate = accountTransactions.Count != 0 ? DateConverter.DateTimeToLong(accountTransactions.Last().TransactionDate) : 0,
                    UserId              = account.UserId
                };
                accountDetailList.Add(accountDetail);
            }
            return(accountDetailList);
        }
        public IHttpActionResult GetAllUserBudgets([FromBody] string userId)
        {
            BudgetDTO          budgetDTO;
            List <BudgetDTO>   budgetDtoList          = new List <BudgetDTO>();
            List <Transaction> budgetTransactionsList = new List <Transaction>();

            List <Budget> listBudget = _budgetDBAccess.FindByUser(userId);

            foreach (Budget budget in listBudget)
            {
                budgetTransactionsList = _transactionDBAccess.FindAllBudgetTransactions(budget);

                decimal expendedAmount = _businessService.GetTotalAmount(budgetTransactionsList);

                budgetDTO = new BudgetDTO
                {
                    BudgetId       = budget.BudgetId,
                    BeginingDate   = DateConverter.DateTimeToLong(budget.BeginingDate),
                    EndDate        = DateConverter.DateTimeToLong(budget.EndDate),
                    Amount         = budget.Amount,
                    ExpendedAmount = expendedAmount,
                    CategoryName   = budget.Category.Label,
                    AccountName    = budget.BankAccount.Name,
                    AccountId      = budget.BankAccount.BankAccountId
                };
                budgetDtoList.Add(budgetDTO);
            }
            return(Ok(budgetDtoList));
        }
        public List <LastTransactionDTO> InitializeLastWeekTransactionList()
        {
            List <LastTransactionDTO> list = new List <LastTransactionDTO>();

            for (int i = 0; i < 7; i++)
            {
                DateTime currentDate = DateTime.Now.AddDays(-i);
                list.Add(new LastTransactionDTO
                {
                    Date   = DateConverter.DateTimeToLong(currentDate),
                    Amount = 0
                });
            }
            return(list);
        }