|
6 | 6 | @inject IPortfolioService PortfolioService
|
7 | 7 | @inject IPortfolioEntryService PortfolioEntryService
|
8 | 8 | @inject IMatDialogService MatDialogService
|
| 9 | +@inject IMatToaster Toaster |
9 | 10 |
|
10 | 11 | <style>
|
11 | 12 | .demo-mat-card {
|
|
33 | 34 | <div class="mat-layout-grid-cell mat-layout-grid-cell-span-3"></div>
|
34 | 35 | <div class="mat-layout-grid-cell mat-layout-grid-cell-span-6">
|
35 | 36 | <MatH5>Portfolios</MatH5>
|
36 |
| - @if (Portfolios != null) |
| 37 | + @if (PortfoliosWithEntries != null) |
37 | 38 | {
|
38 |
| - @foreach (var activePortfolio in Portfolios) |
| 39 | + @foreach (var portfolioWithEntries in PortfoliosWithEntries) |
39 | 40 | {
|
40 | 41 | <MatCard class="demo-mat-card" OnCli>
|
41 | 42 | <MatCardContent>
|
|
45 | 46 | <div class="mat-layout-grid-cell mat-layout-grid-cell-span-6">
|
46 | 47 | <MatHeadline6 class="clear-margin">
|
47 | 48 | <MatChipSet Style="align-items: center">
|
48 |
| - <MatH5 Class="clear-margin">@activePortfolio.Item1.Name</MatH5> |
49 |
| - <MatChip Style="vertical-align: center" Label="@CurrencyUtils.GetCurrencyLabel(activePortfolio.Item1.Currency)"/> |
| 49 | + <MatH5 Class="clear-margin">@portfolioWithEntries.Item1.Name</MatH5> |
| 50 | + <MatChip Style="vertical-align: center" Label="@CurrencyUtils.GetCurrencyLabel(portfolioWithEntries.Item1.Currency)"/> |
50 | 51 | </MatChipSet>
|
51 | 52 | </MatHeadline6>
|
52 | 53 | </div>
|
53 | 54 | <div class="mat-layout-grid-cell mat-layout-grid-cell-span-6" style="text-align: right;">
|
54 |
| - <MatIconButton Icon="edit" OnClick="() => EditPortfolio(activePortfolio.Item1)"></MatIconButton> |
55 |
| - <MatIconButton Icon="delete" OnClick="() => DeletePortfolio(activePortfolio.Item1)"></MatIconButton> |
| 55 | + <MatIconButton Icon="edit" OnClick="() => EditPortfolio(portfolioWithEntries.Item1)"></MatIconButton> |
| 56 | + <MatIconButton Icon="delete" OnClick="() => DeletePortfolio(portfolioWithEntries.Item1)"></MatIconButton> |
56 | 57 | </div>
|
57 | 58 | </div>
|
58 | 59 | </div>
|
59 | 60 | </div>
|
60 | 61 | <div style="padding: 1rem">
|
61 |
| - <MatButton Label="View" Style="margin-right: 1rem;" OnClick="() => ViewPortfolio(activePortfolio.Item1)"></MatButton> |
62 |
| - @if (activePortfolio.Item2.Count > 0) |
| 62 | + <MatButton Label="View" Style="margin-right: 1rem;" OnClick="() => ViewPortfolio(portfolioWithEntries.Item1)"></MatButton> |
| 63 | + @if (portfolioWithEntries.Item2.Count > 0) |
63 | 64 | {
|
64 |
| - @foreach (var entry in activePortfolio.Item2) |
| 65 | + @foreach (var entry in portfolioWithEntries.Item2) |
65 | 66 | {
|
66 | 67 | <MatButton Outlined="true" Style="margin-right: 1em;" Label="@entry.Symbol.ToUpper()" OnClick='() => NavigationManager.NavigateTo($"/entries/{entry.Id}")'></MatButton>
|
67 | 68 | }
|
68 | 69 | }
|
69 | 70 | else
|
70 | 71 | {
|
71 |
| - <MatButton Icon="add" Outlined="true" OnClick="() => AddNewEntryToPortfolio(activePortfolio.Item1)" Label="Add entry"></MatButton> |
| 72 | + <MatButton Icon="add" Outlined="true" OnClick="() => AddNewEntryToPortfolio(portfolioWithEntries.Item1)" Label="Add entry"></MatButton> |
72 | 73 | }
|
73 | 74 | </div>
|
74 | 75 | </MatCardContent>
|
|
88 | 89 |
|
89 | 90 | @code
|
90 | 91 | {
|
91 |
| - protected List<Tuple<Portfolio, List<PortfolioEntry>>> Portfolios; |
92 |
| - |
93 |
| - protected ISummaryService.Summary portfolioSummary = new(1341m, 1.8m, 9982.489m, 1000m); |
94 |
| - |
95 |
| - protected List<PortfolioEntry> activePortfolioEntries = new List<PortfolioEntry>() |
96 |
| - { |
97 |
| - new("btc", 1, 1), |
98 |
| - new("ada", 1, 2), |
99 |
| - new("eth", 1, 3), |
100 |
| - new("ltc", 1, 4), |
101 |
| - new("link", 1, 5), |
102 |
| - }; |
103 |
| - |
104 |
| - protected List<decimal> portfolioHoldings = new() |
105 |
| - { |
106 |
| - 44.8886m, |
107 |
| - 28.18m, |
108 |
| - 10.116m, |
109 |
| - 9.38m, |
110 |
| - 2.70m, |
111 |
| - }; |
112 |
| - |
113 |
| - protected List<PortfolioEntryRow> portfolioEntryRows = new() |
114 |
| - { |
115 |
| - new("btc", 57644.42m, 1.35m, 44.76m), |
116 |
| - new("ada", 1.36m, 0.58m, 28.18m), |
117 |
| - new("eth", 3279.64m, 10.95m, 27.11m), |
118 |
| - new("ltc", 291.55m, 7.20m, 9.38m), |
119 |
| - new("link", 42.20m, -5.19m, 2.70m) |
120 |
| - }; |
| 92 | + protected List<Tuple<Portfolio, List<PortfolioEntry>>> PortfoliosWithEntries; |
121 | 93 |
|
122 | 94 | protected record PortfolioEntryRow(string symbol, decimal currentPrice, decimal relativeChange, decimal percentage);
|
123 | 95 |
|
|
128 | 100 |
|
129 | 101 | private void LoadPortfolios()
|
130 | 102 | {
|
131 |
| - Portfolios = PortfolioService.GetPortfolios().Select( |
| 103 | + PortfoliosWithEntries = PortfolioService.GetPortfolios().Select( |
132 | 104 | portfolio => new Tuple<Portfolio, List<PortfolioEntry>>(
|
133 | 105 | portfolio,
|
134 | 106 | PortfolioEntryService.GetPortfolioEntries(portfolio.Id)
|
135 | 107 | )
|
136 | 108 | ).ToList();
|
137 | 109 | }
|
138 | 110 |
|
139 |
| - |
140 |
| - protected override async Task OnInitializedAsync() |
141 |
| - { |
142 |
| - //_existingPortfolios = PortfolioService.GetPortfolios(); |
143 |
| - } |
144 |
| - |
145 |
| - public void SelectionChangedEvent(object row) |
146 |
| - { |
147 |
| - if (row == null) |
148 |
| - { |
149 |
| - } |
150 |
| - else |
151 |
| - { |
152 |
| - NavigationManager.NavigateTo($"entries"); |
153 |
| - } |
154 |
| - } |
155 |
| - |
156 | 111 | private void EditPortfolio(Portfolio activePortfolioItem1)
|
157 | 112 | {
|
158 |
| - Console.WriteLine($"About to edit {activePortfolioItem1.Name}"); |
| 113 | + NavigationManager.NavigateTo($"/editportfolio/{activePortfolioItem1.Id}"); |
159 | 114 | }
|
160 | 115 |
|
161 | 116 | private async void DeletePortfolio(Portfolio portfolio)
|
|
166 | 121 | PortfolioService.DeletePortfolio(portfolio);
|
167 | 122 | LoadPortfolios();
|
168 | 123 | StateHasChanged();
|
| 124 | + Toaster.Add($"Portfolio \"{portfolio.Name}\" sucessfully deleted", MatToastType.Info, "", ""); |
169 | 125 | }
|
170 | 126 | }
|
171 | 127 |
|
|
0 commit comments