/// <summary> /// The ExecuteAsync /// </summary> /// <param name="cancellationToken">The cancellationToken<see cref="CancellationToken"/></param> /// <returns>The <see cref="Task"/></returns> public async Task ExecuteAsync(CancellationToken cancellationToken) { try { using (var scope = _scopeFactory.CreateScope()) { var dbContext = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); var UsersLst = dbContext.ApplicationUsers.ToList <ApplicationUser>(); TipAccountStats.UsersCount = UsersLst.Count(); // List all account address TipAccountStats.AddressLst = dbContext.ApplicationUsers.Select(x => x.Address).ToList(); // Reset the balance double TotalBalance = 0; int TotalTransactions = 0; long TotalAmountTransactions = 0; foreach (var account in UsersLst) { if (account.Address != null) { RiseManager rm = new RiseManager(); TotalBalance += await rm.AccountBalanceAsync(account.Address); var tx = TransactionsFetcher.FetchAllUserTransactions(account.Address).Result.transactions.ToList(); TotalTransactions += tx.Count(); TotalAmountTransactions += tx.Sum(x => x.amount / 100000000); if (tx == null && account.UserName == null) { dbContext.Users.Remove(account); dbContext.SaveChanges(); } } } TipAccountStats.TotalBalance = TotalBalance; TipAccountStats.TotalTransactions = TotalTransactions; TipAccountStats.TotalAmountTransactions = TotalAmountTransactions; TipAccountStats.LastGenerated = DateTime.Now; } } catch (Exception e) { Console.Write(e.InnerException); } }
public async Task <PartialViewResult> TransactionsTablePartialViewAsync(string address = "") { try { TransactionsViewModel transactionsViewModel = new TransactionsViewModel { coinQuoteCol = CoinQuoteResult.Current, CoinbaseBtcQuoteResult = CoinbaseBtcQuote.Current, DelegateResult = DelegateResult.Current }; if (address?.Length == 0) { transactionsViewModel.TransactionsResult = TransactionsResult.Current; } else { var account = DelegateResult.Current.Delegates.Where(x => x.Username.Contains(address.ToLower()) || x.Address == address).OrderBy(j => j.Username.Length).FirstOrDefault(); if (account != null) { transactionsViewModel.TransactionsResult = await TransactionsFetcher.FetchAllUserTransactions(account.Address); } else { transactionsViewModel.TransactionsResult = await TransactionsFetcher.FetchAllUserTransactions(address); } } return(PartialView("_TransactionsTablePartial", transactionsViewModel)); } catch (Exception ex) { var log = new Log(); log.LogMessage(ex.Message + " " + ex.StackTrace + " " + ex.InnerException); _appdb.Logger.Add(log); _appdb.SaveChangesAsync().Wait(); return(null); } }