public async Task <object> Handle(Users.Query cmd, CancellationToken cancellationToken) { var users = await _storage.GetUserEmailIdPairs(); var result = new List <UserView>(); foreach (var(email, userId) in users) { var guid = new System.Guid(userId); var user = await _storage.GetUser(guid); var options = await _portfolio.GetOwnedOptions(guid); var notes = await _portfolio.GetNotes(guid); var stocks = await _portfolio.GetStocks(guid); var alerts = await _alerts.GetAlerts(guid); var u = new UserView(user, stocks, options, notes, alerts); result.Add(u); } return(result.OrderByDescending(u => u.LastLogin)); }
public async Task <ActionResult> ActiveAccountsAsync() { var users = await _storage.GetUserEmailIdPairs(); var total = 0; var loggedIn = 0; var tableHtml = new StringBuilder(); tableHtml.Append(@" <table> <tr> <th>Email</th> <th>User Id</th> <th>Last Login</th> <th>Verified</th> <th>Level</th> <th>Stocks</th> <th>Options</th> <th>Notes</th> </tr>"); foreach (var(email, userId) in users) { tableHtml.AppendLine($"<tr>"); tableHtml.Append($"<td>{email}</td>"); tableHtml.Append($"<td>{userId}</td>"); var guid = new System.Guid(userId); var user = await _storage.GetUser(guid); tableHtml.Append($"<td>{user?.LastLogin?.ToString()}</td>"); tableHtml.Append($"<td>{user?.Verified}</td>"); tableHtml.Append($"<td>{user?.SubscriptionLevel}</td>"); var options = await _portfolio.GetOwnedOptions(guid); var notes = await _portfolio.GetNotes(guid); var stocks = await _portfolio.GetStocks(guid); tableHtml.Append($"<td>{stocks.Count()}</td>"); tableHtml.Append($"<td>{options.Count()}</td>"); tableHtml.Append($"<td>{notes.Count()}</td>"); tableHtml.AppendLine("</tr>"); total++; if (user != null && user.LastLogin.HasValue) { loggedIn++; } } tableHtml.AppendLine("</table>"); var body = $@"<html> <body> <h3>Users: {total}</h3> <h4>Logged In: {loggedIn}</h4> ${tableHtml.ToString()} </body> </html>"; return(new ContentResult { Content = body, ContentType = "text/html" }); }