public async Task <WalletDetailsDto> GetWalletDetailsAsync(string userId, int walletId) { WalletDetailsDto targetWallet = await this.dbContext.Wallets .Where(w => w.Id == walletId) .Select(w => new WalletDetailsDto { Currency = w.Currency.Code, CurrentBalance = w.MoneyAmount, WalletId = w.Id, WalletName = w.Name, Categories = w.Categories.Select(c => new WalletDetailsCategoryDto { CategoryId = c.Id, CategoryName = c.Name, TotalExpenses = c.Records.Where(r => r.Type == RecordType.Expense).Sum(r => r.Amount), TotalIncomes = c.Records.Where(r => r.Type == RecordType.Income).Sum(r => r.Amount), RecordsCount = c.Records.Count(), BadgeColor = c.BadgeColor, }), }) .FirstOrDefaultAsync(); if (targetWallet == null) { throw new ArgumentNullException(GlobalConstants.WalletNotExist); } decimal totalWalletExpensesLast30days = this.dbContext.Records .Where(r => r.Category.WalletId == walletId && r.Type == RecordType.Expense && r.CreatedOn <= DateTime.UtcNow && r.CreatedOn >= DateTime.UtcNow.AddDays(-30)) .Sum(r => r.Amount); decimal totalWalletIncomesLast30days = this.dbContext.Records .Where(r => r.Category.WalletId == walletId && r.Type == RecordType.Income && r.CreatedOn <= DateTime.UtcNow && r.CreatedOn >= DateTime.UtcNow.AddDays(-30)) .Sum(r => r.Amount); int totalRecordsCountLast30Days = this.dbContext.Records .Where(r => r.Category.WalletId == walletId && r.CreatedOn <= DateTime.UtcNow && r.CreatedOn >= DateTime.UtcNow.AddDays(-30)) .Count(); targetWallet.TotalRecordsCountLast30Days = totalRecordsCountLast30Days; targetWallet.TotalWalletExpensesLast30Days = totalWalletExpensesLast30days; targetWallet.TotalWalletIncomesLast30Days = totalWalletIncomesLast30days; targetWallet.Records = await this.dbContext.Records .Where(r => r.Category.WalletId == walletId) .Select(r => new WalletDetailsRecordDto { Id = r.Id, Amount = r.Amount, CategoryId = r.CategoryId, CategoryName = r.Category.Name, CreatedOn = r.CreatedOn, Description = r.Description, CategoryBadgeColor = r.Category.BadgeColor, }) .ToListAsync(); return(targetWallet); }
public async Task <WalletDetailsDto> GetWalletDetails(string walletAddress) { var walletDetails = new WalletDetailsDto(); walletDetails.Balance = await GetBalance(walletAddress); var chain = await GetBlockchain(); walletDetails.Transactions = chain.SelectMany(block => block.Transactions) .Where(tx => tx.FromAddress.Equals(walletAddress) || tx.ToAddress.Equals(walletAddress)).ToList(); walletDetails.WalletAddress = walletAddress; return(walletDetails); }
public async Task <IActionResult> OnGet(string walletAddress) { WalletDetails = await _blockchainService.GetWalletDetails(walletAddress); return(Page()); }