public ActionResult <IEnumerable <Account> > ViewAllAccounts() { var allAccounts = _bankService.GetAccounts(); if (allAccounts == null) { return(BadRequest()); } return(allAccounts.ToList()); }
public async Task <TraderService.ResponseViewModel> BuyStock(Guid requestId, Guid userId) { try { var account = (await _bankService.GetAccounts(userId)).Accounts.FirstOrDefault(); var portfolio = await _portfolioService.GetPortfolioByUser(userId); if (account == null || portfolio == null) { throw new ArgumentException("Either account or portfolio wasn't found"); } return(await _traderService.BuyShare(requestId, account.AccountId, portfolio.PortfolioId)); } catch (System.Exception) { return(null); } }
public async Task <TraderService.RequestViewModel> SellShare(Guid userId, Guid shareId, int amount) { try { var accounts = await _bankService.GetAccounts(userId); var portfolio = await _portfolioService.GetPortfolioByUser(userId); if (accounts.Accounts.FirstOrDefault() == null || portfolio == null) { throw new ArgumentException("Either account or portfolio wasn't found"); } return(await _traderService.SellShare(accounts.Accounts.FirstOrDefault().AccountId, portfolio.PortfolioId, shareId, amount)); } catch (System.Exception) { return(null); } }
static void Main(string[] args) { service.CreateAccount( new Account { AccountType = AccountType.Base, Balance = 300, FirstName = "Vasya", LastName = "Pupkin" }); service.CreateAccount( new Account { AccountType = AccountType.Gold, Balance = 500, FirstName = "pasha", LastName = "vaskin" }); service.CreateAccount( new Account { AccountType = AccountType.Silver, Balance = 400, FirstName = "sasha", LastName = "pashkin" }); var account = service.GetAccounts(); foreach (var item in account) { Console.WriteLine(item); } Console.WriteLine("Add balance"); foreach (var item in account) { service.AddBalance(item.Id, 50); } foreach (var item in account) { Console.WriteLine(item); } Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("Remove balance"); foreach (var item in account) { service.RemoveBalance(item.Id, 50); } foreach (var item in account) { Console.WriteLine(item); } Console.ReadKey(); }
public ActionResult List() { var accounts = _service.GetAccounts(User.Identity.GetUserId()); return(View(accounts)); }