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 <CommandResponse <OwnedOption> > Handle(Command cmd, CancellationToken cancellationToken) { var user = await _accountStorage.GetUser(cmd.UserId); if (user == null) { return(CommandResponse <OwnedOption> .Failed( "Unable to find user account for options operation")); } if (user.State.Verified == null) { return(CommandResponse <OwnedOption> .Failed( "Please verify your email first before you can record option transaction")); } var optionType = (OptionType)Enum.Parse(typeof(OptionType), cmd.OptionType, ignoreCase: true); var options = await _storage.GetOwnedOptions(cmd.UserId); var option = options.SingleOrDefault(o => o.IsMatch(cmd.Ticker, cmd.StrikePrice, optionType, cmd.ExpirationDate.Value)); if (option == null) { option = new OwnedOption( cmd.Ticker, cmd.StrikePrice, optionType, cmd.ExpirationDate.Value, cmd.UserId); } option.Buy(cmd.NumberOfContracts, cmd.Premium, cmd.Filled.Value, cmd.Notes); await _storage.Save(option, cmd.UserId); return(CommandResponse <OwnedOption> .Success(option)); }
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" }); }