Ejemplo n.º 1
0
 public async Task <ActionResult <ResultFormat> > Get([FromQuery] TransactionsQuery query)
 {
     return(new ResultFormat()
     {
         Results = (await _Repository.GetTransactions(query)).ToList()
     });
 }
Ejemplo n.º 2
0
    public async Task <TransactionData> GetTransactionData(string authId)
    {
        // TODO - Unit tests
        var transactions = await _transactionsRepository.GetTransactions(authId);

        var categoryTotals = await _transactionsRepository.GetCategoryTotals(authId);

        var totals = await _transactionsRepository.GetTransactionTotals(authId);

        return(new TransactionData(transactions, categoryTotals, totals.TotalIncoming, totals.TotalOutgoing, totals.NetPosition));
    }
Ejemplo n.º 3
0
        public IReadOnlyList <UserBalance> GetBalances(string settlementId)
        {
            var expenses             = _expensesRepository.GetExpenses(settlementId).ToList();
            var expensesSumByWhoPaid = expenses
                                       .GroupBy(e => e.WhoPaid.Id)
                                       .ToDictionary(g => g.Key, g => g.Sum(e => e.Amount));
            var settlementUsers = _settlementUsersRepository.GetSettlementUsers(settlementId)
                                  .ToList();
            var usersCount = settlementUsers.Count();
            var expensesSumByParticipant = settlementUsers
                                           .ToDictionary(u => u.Id, u =>
                                                         Round(expenses
                                                               .Where(e => e.Participants.IsNullOrEmpty() || e.Participants.Any(p => p.Id == u.Id))
                                                               .Sum(e => e.Amount / (e.Participants.IsNullOrEmpty() ? usersCount : e.Participants.Count))));
            var transactions = _transactionsRepository.GetTransactions(settlementId)
                               .ToList();
            var outgoingTransactionsSumByUser = transactions
                                                .GroupBy(t => t.From.Id)
                                                .ToDictionary(g => g.Key, g => g.Sum(t => t.Amount));
            var incomingTransactionsSumByUser = transactions
                                                .GroupBy(t => t.To.Id)
                                                .ToDictionary(g => g.Key, g => g.Sum(t => t.Amount));

            return(settlementUsers
                   .Select(u => new UserBalance
            {
                User = u,
                Balance = expensesSumByWhoPaid.GetValueOrDefault(u.Id, 0)
                          - expensesSumByParticipant.GetValueOrDefault(u.Id, 0)
                          + outgoingTransactionsSumByUser.GetValueOrDefault(u.Id, 0)
                          - incomingTransactionsSumByUser.GetValueOrDefault(u.Id, 0)
            })
                   .ToList());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Index()
        {
            var userId       = HttpContext.GetUserId();
            var transactions = await _repo.GetTransactions(userId);

            return(View(transactions));
        }
Ejemplo n.º 5
0
        public CLOPEСlusterer(ITransactionsRepository <T, K> repository, decimal r)
        {
            this.repository = repository;
            this.r          = r;

            int id = 1;

            AddEmptyCluster = delegate()
            {
                var newCluster = new Cluster <T, K>(id++);
                clusters.Add(newCluster);
            };

            transactions = repository.GetTransactions();
            clusters     = new List <Cluster <T, K> >();
            AddEmptyCluster();
        }
Ejemplo n.º 6
0
        public void GetBalances_WhenTransactionsExist()
        {
            var userA = CreateSettlementUser();
            var userB = CreateSettlementUser();
            var userC = CreateSettlementUser();
            var users = new[] { userA, userB, userC };

            _settlementUsersRepository.GetSettlementUsers(_settlementId)
            .Returns(users);
            var expenses = new[]
            {
                new Expense {
                    WhoPaid = userA, Amount = 9
                }
            };

            _expensesRepository.GetExpenses(_settlementId)
            .Returns(expenses);
            var transactions = new[]
            {
                new Transaction {
                    From = userB, To = userA, Amount = 2
                },
                new Transaction {
                    From = userC, To = userA, Amount = 1
                }
            };

            _transactionsRepository.GetTransactions(_settlementId)
            .Returns(transactions);
            var provider = CreateBalancesProvider();

            var balances = provider.GetBalances(_settlementId);

            Assert.Collection(balances,
                              item => Assert.Equal(3M, item.Balance),
                              item => Assert.Equal(-1M, item.Balance),
                              item => Assert.Equal(-2M, item.Balance)
                              );
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Index()
        {
            var user = await _userManager.GetUserAsync(User);

            return(View(await _transactionRepository.GetTransactions(user.Id)));
        }
Ejemplo n.º 8
0
        public IActionResult Index()
        {
            List <Transactions> transactionsList = _transactionsRepository.GetTransactions().ToList();
            List <TradeResults> tradeResults     = new List <TradeResults>();
            decimal?            total            = 0;
            decimal?            percentageTotal  = 0;

            foreach (var item in transactionsList)
            {
                TradeResults tradeResult = new TradeResults();
                tradeResult.Id         = item.Id;
                tradeResult.StartDate  = item.StartDate;
                tradeResult.StartPrice = item.StartPrice;
                tradeResult.EndPrice   = item.EndPrice;
                tradeResult.EndDate    = item.EndDate;
                tradeResult.Symbol     = item.Symbol;
                tradeResult.Shares     = item.Shares;

                decimal?profitLossPerShare = tradeResult.EndPrice - tradeResult.StartPrice;

                if (!String.IsNullOrWhiteSpace(tradeResult.EndDate))
                {
                    tradeResult.ProfitLoss = Math.Round((decimal)((tradeResult.EndPrice - tradeResult.StartPrice)) * (decimal)tradeResult.Shares, 2);

                    total += tradeResult.ProfitLoss;
                    tradeResult.Percentage = Math.Round((decimal)(profitLossPerShare / tradeResult.StartPrice) * 100, 2);
                    percentageTotal       += tradeResult.Percentage;
                }


                tradeResults.Add(tradeResult);
            }



            ViewBag.Total           = total;
            ViewBag.PercentageTotal = percentageTotal;


            int     k             = 1;
            String  jsonChartData = "[0, 0], ";
            decimal runningTotal  = 0;

            foreach (var item in tradeResults)
            {
                if (!String.IsNullOrWhiteSpace(item.EndDate))
                {
                    runningTotal   = (decimal)(runningTotal + item.ProfitLoss);
                    jsonChartData += "[" + k + ", " + runningTotal + "]";

                    if ((k) != tradeResults.Count)
                    {
                        jsonChartData += ", ";
                    }
                }

                k++;
            }

            ViewBag.JsonChartData = jsonChartData;

            return(View(tradeResults));
        }
Ejemplo n.º 9
0
 private async Task <List <Transaction> > GetTransactions(TransactionsQuery query)
 {
     return((await _Repository.GetTransactions(query)).ToList());
 }
 public ActionResult GetAll(string settlementId)
 {
     return(Ok(_transactionsRepository.GetTransactions(settlementId)));
 }
        public IEnumerable <Transaction> GetTransactions()
        {
            var transactions = TransactionsRepository.GetTransactions();

            return(transactions);
        }
Ejemplo n.º 12
0
 public List <Transaction> GetTransactions()
 {
     return(_transactionsRepository.GetTransactions());
 }
        public async Task <IList <TransactionEntity> > GetTransactions()
        {
            var rates = await transactionsRepository.GetTransactions().ConfigureAwait(false);

            return(rates);
        }