Skip to content

Commit f28c337

Browse files
committed
Added a new page that allows the user to create new portfolio entries and added a button that leads to this page to the "New portfolio" page.
1 parent 086a21e commit f28c337

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
@page "/newportfolioentry/{portfolioId:int}"
2+
@using Model
3+
@using Services
4+
@using Utils
5+
@using System.ComponentModel.DataAnnotations
6+
@using CryptoStatsSource
7+
@using CryptoStatsSource.model
8+
@inject IPortfolioService PortfolioService
9+
@inject IPortfolioEntryService PortfolioEntryService
10+
@inject ICryptoStatsSource CryptoStatsSource;
11+
@inject IMatDialogService MatDialogService
12+
@inject IMatToaster Toaster
13+
14+
15+
<style>
16+
.demo-mat-card {
17+
max-width: 400px;
18+
margin-bottom: 2em;
19+
}
20+
21+
.demo-mat-card-content {
22+
padding: 1rem;
23+
}
24+
25+
.demo-mat-card-clean-margin {
26+
margin: 0px;
27+
}
28+
</style>
29+
30+
<div class="mat-layout-grid">
31+
<div class="mat-layout-grid-inner">
32+
<div class="mat-layout-grid-cell">
33+
<MatH5>Add a new portfolio entry for @Portfolio.Name</MatH5>
34+
<MatTable Items="@AvailableCryptocurrencies" Striped="true" RowClass="tester" PageSize="10"
35+
FilterByColumnName="Symbol" DebounceMilliseconds="150" class="mat-elevation-z5" OnRowDbClick="(w) => { OnAvailableCurrencyClicked((Cryptocurrency) w); }">
36+
37+
<MatTableHeader>
38+
<th>Name</th>
39+
<th>Symbol</th>
40+
<th></th>
41+
</MatTableHeader>
42+
<MatTableRow>
43+
<td>@context.Name</td>
44+
<td>@context.Symbol</td>
45+
<td><MatButton Icon="add" Alignment OnClick="() => { OnAvailableCurrencyClicked(context);}" Style="float: right"></MatButton></td>
46+
</MatTableRow>
47+
</MatTable>
48+
</div>
49+
<div class="mat-layout-grid-cell">
50+
<MatH5>Current portfolio entries</MatH5>
51+
<MatTable Items="@PortfolioEntries" Striped="true" AllowSelection="true" RowClass="tester" class="mat-elevation-z5" ShowPaging="false" PageSize="9999">
52+
<MatTableHeader>
53+
<th>Name</th>
54+
<th>Symbol</th>
55+
</MatTableHeader>
56+
<MatTableRow>
57+
<td>@context.Symbol</td>
58+
<td>@context.Symbol</td>
59+
</MatTableRow>
60+
</MatTable>
61+
</div>
62+
63+
</div>
64+
</div>
65+
66+
67+
@code
68+
{
69+
[Parameter]
70+
public int PortfolioId { get; set; }
71+
72+
protected Portfolio Portfolio;
73+
protected List<PortfolioEntry> PortfolioEntries;
74+
75+
protected List<Cryptocurrency> AvailableCryptocurrencies;
76+
77+
protected override void OnInitialized()
78+
{
79+
Portfolio = PortfolioService.GetPortfolio(PortfolioId);
80+
PortfolioEntries = PortfolioEntryService.GetPortfolioEntries(PortfolioId);
81+
}
82+
83+
protected override async Task OnInitializedAsync()
84+
{
85+
var entriesSymbols = PortfolioEntries.Select(e => e.Symbol);
86+
AvailableCryptocurrencies = (await CryptoStatsSource.GetAvailableCryptocurrencies()).FindAll(
87+
c => !entriesSymbols.Contains(c.Symbol)
88+
).OrderBy(c => c.Symbol.Length).ToList();
89+
90+
91+
}
92+
93+
private void OnAvailableCurrencyClicked(Cryptocurrency cryptocurrency)
94+
{
95+
Console.WriteLine("OnAvailableCurrencyClicked");
96+
PortfolioEntryService.CreatePortfolioEntry(cryptocurrency.Symbol, PortfolioId);
97+
AvailableCryptocurrencies.Remove(cryptocurrency);
98+
PortfolioEntries = PortfolioEntryService.GetPortfolioEntries(PortfolioId);
99+
}
100+
}

0 commit comments

Comments
 (0)