Esempio n. 1
0
        public TransactionViewModel[] GetTransactions(int walletId, TransactionType?type, int?categoryId, DateTime?fromDate, DateTime?toDate, int?limit)
        {
            var wallet = _walletsService.GetAsync(walletId);

            if (wallet == null)
            {
                throw new NotFoundException("Wallet not found");
            }

            var transactions = _transactionsService.GetMany(walletId, type, categoryId, fromDate, toDate, limit);
            var categoryIds  = transactions.Select(t => t.CategoryId).Distinct().ToArray();
            var categories   = _categoriesService.GetMany(categoryIds).ToDictionary(c => c.Id);

            return(transactions
                   .Select(t => new TransactionViewModel
            {
                CategoryName = categories[t.CategoryId].Name,
                DateTime = t.DateTime,
                Description = t.Description,
                Value = t.Value,
                Type = t.Type
            })
                   .OrderByDescending(t => t.DateTime)
                   .ToArray());
        }