|
1 | 1 | @page "/"
|
2 |
| -@using Model |
3 | 2 | @using Services
|
4 | 3 | @using Utils
|
5 |
| -@inject Microsoft.AspNetCore.Components.NavigationManager NavigationManager |
| 4 | +@using Model |
| 5 | +@inject NavigationManager NavigationManager |
6 | 6 | @inject IPortfolioService PortfolioService
|
7 | 7 | @inject IPortfolioEntryService PortfolioEntryService
|
8 | 8 | @inject IMatDialogService MatDialogService
|
|
26 | 26 | bottom: 1rem;
|
27 | 27 | right: 1rem;
|
28 | 28 | }
|
29 |
| - |
30 |
| - .mat-paper { |
31 |
| - display: flex; |
32 |
| - flex-direction: column; |
33 |
| - justify-content: center; |
34 |
| - align-items: center; |
35 |
| - padding: 1em; |
36 |
| - } |
37 |
| - |
38 | 29 | </style>
|
39 | 30 | <div class="mat-layout-grid mat-layout-grid-align-center">
|
40 | 31 | <div class="mat-layout-grid-inner center">
|
41 | 32 |
|
42 | 33 | <div class="mat-layout-grid-cell mat-layout-grid-cell-span-2"></div>
|
43 | 34 | <div class="mat-layout-grid-cell mat-layout-grid-cell-span-8">
|
44 | 35 | <MatH5>Portfolios</MatH5>
|
45 |
| - @if (PortfoliosWithEntries == null) |
| 36 | + @if (_portfoliosWithEntries == null) |
46 | 37 | {
|
47 | 38 | <MatProgressBar Indeterminate="true"></MatProgressBar>
|
48 | 39 | }
|
49 |
| - else if (PortfoliosWithEntries.Count < 1) |
| 40 | + else if (_portfoliosWithEntries.Count < 1) |
50 | 41 | {
|
51 |
| - <MatPaper Elevation="2"><span>No portfolios were found.</span><div><MatButton Style="margin-top:1em;" Label="Create a new portfolio" OnClick='() => { NavigationManager.NavigateTo($"newportfolio");}'></MatButton></div></MatPaper> |
| 42 | + <MatPaper Elevation="2"> |
| 43 | + <span>No portfolios were found.</span> |
| 44 | + <div> |
| 45 | + <MatButton Style="margin-top:1em;" Label="Create a new portfolio" OnClick='() => { NavigationManager.NavigateTo($"newportfolio"); }'></MatButton> |
| 46 | + </div> |
| 47 | + </MatPaper> |
52 | 48 | }
|
53 | 49 | else
|
54 | 50 | {
|
55 |
| - @foreach (var portfolioWithEntries in PortfoliosWithEntries) |
| 51 | + @foreach (var portfolioWithEntries in _portfoliosWithEntries) |
56 | 52 | {
|
57 | 53 | <MatCard class="demo-mat-card" OnCli>
|
58 | 54 | <MatCardContent>
|
|
96 | 92 | <div class="mat-layout-grid-cell mat-layout-grid-cell-span-2"></div>
|
97 | 93 | </div>
|
98 | 94 | </div>
|
99 |
| -<MatFAB Class="app-fab--absolute" Icon="@MatIconNames.Add" Label="Add a new portfolio" OnClick='() => { NavigationManager.NavigateTo($"newportfolio");}'></MatFAB> |
| 95 | +<MatFAB Class="app-fab--absolute" Icon="@MatIconNames.Add" Label="Add a new portfolio" OnClick='() => { NavigationManager.NavigateTo($"newportfolio"); }'></MatFAB> |
100 | 96 |
|
101 | 97 |
|
102 | 98 | @code
|
103 | 99 | {
|
104 |
| - protected List<Tuple<Portfolio, List<PortfolioEntry>>> PortfoliosWithEntries; |
| 100 | + // list of portfolios with entries mapped to them |
| 101 | + private List<Tuple<Portfolio, List<PortfolioEntry>>> _portfoliosWithEntries; |
105 | 102 |
|
106 | 103 | protected record PortfolioEntryRow(string symbol, decimal currentPrice, decimal relativeChange, decimal percentage);
|
107 | 104 |
|
|
112 | 109 |
|
113 | 110 | private void LoadPortfolios()
|
114 | 111 | {
|
115 |
| - PortfoliosWithEntries = PortfolioService.GetPortfolios().Select( |
| 112 | + _portfoliosWithEntries = PortfolioService.GetPortfolios().Select( |
116 | 113 | portfolio => new Tuple<Portfolio, List<PortfolioEntry>>(
|
117 | 114 | portfolio,
|
118 | 115 | PortfolioEntryService.GetPortfolioEntries(portfolio.Id)
|
|
127 | 124 |
|
128 | 125 | private async void DeletePortfolio(Portfolio portfolio)
|
129 | 126 | {
|
| 127 | + // let user confirm whether he wants to delete the portfolio |
130 | 128 | var result = await MatDialogService.ConfirmAsync("Do you really wish to delete this portfolio including all of it's portfolio entries and market orders?");
|
131 | 129 | if (result)
|
132 | 130 | {
|
| 131 | + // delete portfolio |
133 | 132 | PortfolioService.DeletePortfolio(portfolio);
|
| 133 | + // reload the portfolio list |
134 | 134 | LoadPortfolios();
|
| 135 | + // refresh the UI |
135 | 136 | StateHasChanged();
|
136 | 137 | Toaster.Add($"Portfolio \"{portfolio.Name}\" sucessfully deleted", MatToastType.Info, "", "");
|
137 | 138 | }
|
|
141 | 142 | {
|
142 | 143 | NavigationManager.NavigateTo($"/newportfolioentry/{portfolio.Id}");
|
143 | 144 | }
|
144 |
| - |
| 145 | + |
145 | 146 | private void ViewPortfolio(Portfolio portfolio)
|
146 | 147 | {
|
147 | 148 | NavigationManager.NavigateTo($"/portfolios/{portfolio.Id}");
|
|
0 commit comments