Skip to content

Commit

Permalink
New UI implemented, bootstrap added, identity and stock buy&sell disa…
Browse files Browse the repository at this point in the history
…bled temporarily
  • Loading branch information
HordeBies committed May 7, 2023
1 parent c5adf32 commit 6ffef21
Show file tree
Hide file tree
Showing 20 changed files with 778 additions and 134 deletions.
12 changes: 2 additions & 10 deletions Stocks.Web/Areas/User/Controllers/StocksController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 17,9 @@ public StocksController(IFinnhubStocksService finnhubStocksService, IOptions<Tra
this.tradingOptions = tradingOptions.Value;
}

public async Task<IActionResult> Explore(string? id, bool showAll = false)
public async Task<IActionResult> Explore()
{
var stocksList = await finnhubStocksService.GetStocks();
var top25 = tradingOptions.Top25PopularStocks;
if (!showAll)
stocksList = stocksList.Where(s => top25.Contains(s["symbol"])).ToList();
var model = stocksList.Select(s => new Stock() { StockSymbol = s["symbol"], StockName = s["description"] }).OrderBy(s => s.StockName).ToList();

ViewBag.Stock = id;
ViewBag.ShowAll = showAll;
return View(model);
return View();
}
}
}
9 changes: 6 additions & 3 deletions Stocks.Web/Areas/User/Controllers/TradeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 27,19 @@ public TradeController(IOptions<TradingOptions> tradingOptions, IStocksBuyOrders
public async Task<IActionResult> Index([FromServices] IFinnhubCompanyProfileService finnhubCompanyProfileService, [FromServices] IFinnhubStockPriceQuoteService finnhubStockPriceQuoteService, string? id) //Injected services via parameter because they are not used in other methods
{
if (string.IsNullOrEmpty(id))
id = "MSFT";
return View(new StockTrade());

var quote = await finnhubStockPriceQuoteService.GetStockPriceQuote(id);
var profile = await finnhubCompanyProfileService.GetCompanyProfile(id);
var model = new StockTrade()
{
Price = Convert.ToDouble(quote["c"].ToString()),
CurrentPrice = Convert.ToDouble(quote["c"].ToString()),
Quantity = tradingOptions.DefaultOrderQuantity ?? 0,
StockName = profile["name"].ToString(),
StockSymbol = id
StockSymbol = id,
PreviousClosedPrice = Convert.ToDouble(quote["pc"].ToString()),
ChangePercent = Convert.ToDouble(quote["dp"].ToString()),
DailyChange = Convert.ToDouble(quote["d"].ToString())
};
return View(model);
}
Expand Down
6 changes: 5 additions & 1 deletion Stocks.Web/Areas/User/Models/StockTrade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 4,11 @@ public class StockTrade
{
public string? StockSymbol { get; set; }
public string? StockName { get; set; }
public double Price { get; set; }
public double CurrentPrice { get; set; }
public double PreviousClosedPrice { get; set; }
public uint Quantity { get; set; }
public double ChangePercent { get; set; }// In percentage
public double DailyChange { get; set; }// In USD
public int SharesOwned { get; set; }
}
}
4 changes: 2 additions & 2 deletions Stocks.Web/Areas/User/Views/Home/Beginner.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 13,7 @@
<h3>Want to learn how to trade? You're in the right place.</h3>
<h3>
<span class="text-success font-italic">Scroll down</span> to view
some basic concepts and our top 10 active stocks at a given moment.
some basic concepts and our top 25 active stocks at a given moment.
</h3>
</div>
</section>
Expand Down Expand Up @@ -43,7 43,7 @@
</li>
</ul>
</div>
@* TODO: Add Most Active Stocks here *@
<vc:popular-stocks></vc:popular-stocks>
</div>

@section Header
Expand Down
8 changes: 4 additions & 4 deletions Stocks.Web/Areas/User/Views/Home/UserHome.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 6,7 @@
<div class="container">
<div class="row">
<div class="col-lg-3">
<a class="card-a" href="#">
<a class="card-a" asp-area="User" asp-controller="Stocks" asp-action="Explore">
<div class="card bg-transparent home-card mt-3">
<img src="~/images/explore.png" style="width:7em;" class="col-logo" />
<div class="card-body d-block">
Expand All @@ -21,7 21,7 @@
</a>
</div>
<div class="col-lg-3">
<a class="card-a" href="#">
<a class="card-a" asp-area="User" asp-controller="Trade" asp-action="Index">
<div class="card bg-transparent home-card mt-3">
<img src="~/images/trade.png" style="width:7em;" class="col-logo" />
<div class="card-body d-block">
Expand All @@ -38,7 38,7 @@
</a>
</div>
<div class="col-lg-3">
<a class="card-a" href="#">
<a class="card-a" asp-area="User" asp-controller="Portfolio" asp-action="Index">
<div class="card bg-transparent home-card mt-3">
<img src="~/images/investment.png" style="width:7em;" class="col-logo" />
<div class="card-body d-block">
Expand All @@ -55,7 55,7 @@
</a>
</div>
<div class="col-lg-3">
<a class="card-a" href="#">
<a class="card-a" asp-area="User" asp-controller="Home" asp-action="Beginner">
<div class="card bg-transparent home-card mt-3">
<img src="~/images/instructions.png" style="width:7em;" class="col-logo" />
<div class="card-body d-block">
Expand Down
113 changes: 63 additions & 50 deletions Stocks.Web/Areas/User/Views/Stocks/Explore.cshtml
Original file line number Diff line number Diff line change
@@ -1,56 1,69 @@
@model IEnumerable<Stock>

@{
ViewBag.Title = "Explore";
ViewBag.CurrentUrl = "~/Explore";
}

<div class="text-grey ml">
<span>Stocks</span>
<i class="fa-solid fa-caret-right"></i>
<span>Explore</span>
<div class="row">
<div class="col-8 p-0 card shadow border-0 my-4">
<div class="card-header bg-primary bg-gradient ml-0 py-3">
<div class="row">
<div class="col-12 text-center">
<h2 class="text-white pt-2">Explore</h2>
</div>
</div>
</div>
<div class="card-body p-4">
<table id="tblData" class="table table-bordered table-striped w-100">
<thead>
<tr>
<th>Stock Symbol</th>
<th>Company Name</th>
<th class="text-center">Actions</th>
</tr>
</thead>
</table>
</div>
</div>
<div id="selected-stock-container" class="col-4">
</div>
</div>

<div class="flex stocks-list">
<div class="flex-1" id="stocks-list">
<div class="box">
<div class="flex">
<div class="flex-1">
<h4 class="text-grey mb">Stocks</h4>
</div>
<div class="flex-1 text-right">
@if (ViewBag.ShowAll)
@section Scripts{
<script>
var dataTable;
$(document).ready(function () {
loadDataTable();
})
function loadDataTable() {
dataTable = $('#tblData').DataTable({
"ajax": { url: "@Url.Action("GetAllStocks", "Api")" },
columns: [
{ data: 'stockSymbol', "width": "20%" },
{ data: 'stockName', "width": "45%" },
{
<a href="~/Stocks/Explore?showAll=false" class="mr">Show top 25 stocks</a>
data: 'stockSymbol',
"render": function (data) {
return `
<div class="w-100 pt-2 btn-group" role="group">
<button onClick="showStockDetails('${data}')" class="btn btn-primary mx-2" style="cursor:pointer">
<i class="bi bi-info-circle me-2"></i> Details
</button>
<a class="btn btn-primary mx-2" style="cursor:pointer" href="@(Url.Action("Index","Trade"))/${data}">
<i class="bi bi-arrow-down-up me-2"></i> Trade
</a>
</div>
`;
},
"width": "35%"
}
else
{
<a href="~/Stocks/Explore?showAll=true" class="mr">Show all stocks</a>
}
</div>
</div>

<ul class="list">
@foreach (Stock stock in Model)
{
<li>
<a href="~/Stocks/Explore/@[email protected]">
<h4>@stock.StockName</h4>
<div class="text-grey">(@stock.StockSymbol)</div>
</a>
</li>
]
});
}
function showStockDetails(stockSymbol) {
console.log(stockSymbol);
$.ajax({
type: "GET",
url: "@Url.Action("StockDetailVC","Api")",
data: { stockSymbol: stockSymbol },
success: function (result) {
$("#selected-stock-container").html(result);
}
</ul>
@if (Model.Count() == 0)
{
<div class="mt text-blue">No stocks</div>
}
</div>
</div>
<div class="flex-1" id="stock-details">
@if (ViewBag.Stock != null)
{
<vc:selected-stock stock-symbol="@ViewBag.Stock"></vc:selected-stock>
});
}
</div>
</div>
</script>
}
Loading

0 comments on commit 6ffef21

Please sign in to comment.