4
4
@using Utils
5
5
@inject Microsoft .AspNetCore .Components .NavigationManager NavigationManager
6
6
@inject IPortfolioService PortfolioService
7
+ @inject IPortfolioEntryService PortfolioEntryService
8
+ @inject IMatDialogService MatDialogService
7
9
8
10
<style >
9
11
.demo-mat-card {
30
32
31
33
<div class =" mat-layout-grid-cell mat-layout-grid-cell-span-3" ></div >
32
34
<div class =" mat-layout-grid-cell mat-layout-grid-cell-span-6" >
33
- @if (activePortfolio != null )
35
+ <MatH5 >Portfolios</MatH5 >
36
+ @if (Portfolios != null )
34
37
{
35
- < MatCard class = " demo-mat-card " >
36
- < MatCardContent >
37
- < div class =" demo-mat-card-content " >
38
- < MatHeadline6 class = " clear-margin " >
39
- < MatChipSet Style = " align-items: center " >
40
- < MatH5 Class = " clear-margin " > @activePortfolio.Name </ MatH5 >
41
- <MatChip Style = " vertical-align: center" Label = " @CurrencyUtils.GetCurrencyLabel(activePortfolio.Currency) " / >
42
- </ MatChipSet >
43
- </ MatHeadline6 >
44
- </ div >
45
-
46
- < MatBody2 class = " demo-mat-card-content clear-margin " >
47
- < div class = " mat-layout-grid " >
48
- < div class = " mat-layout-grid-inner " style = " align-items : center " >
49
- < div class = " mat-layout-grid-cell mat-layout-grid-cell-span-6 " >
50
- <MatH4 Class = " clear-margin " > @( CurrencyUtils . Format ( portfolioSummary . MarketValue , activePortfolio . Currency ) ) </ MatH4 >
51
- </ div >
52
- < div class = " mat-layout-grid-cell mat-layout-grid-cell-span-6 " style = " text-align : end " >
53
- @( portfolioSummary . RelativeChange * 100 m ) %
38
+ @foreach ( var activePortfolio in Portfolios )
39
+ {
40
+ < MatCard class =" demo-mat-card" OnCli >
41
+ < MatCardContent >
42
+ < div class = " demo-mat-card-content " >
43
+ < div class = " mat-layout-grid mat-layout-grid-align-center " style = " padding : 0 px ; " >
44
+ <div class = " mat-layout-grid-inner center" >
45
+ < div class = " mat-layout-grid-cell mat-layout-grid-cell-span-6 " >
46
+ < MatHeadline6 class = " clear-margin " >
47
+ < 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) " / >
50
+ </ MatChipSet >
51
+ </ MatHeadline6 >
52
+ </ div >
53
+ <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 >
56
+ </ div >
54
57
</div >
55
58
</div >
56
59
</div >
57
- </ MatBody2 >
58
- </ MatCardContent >
59
- </ MatCard >
60
- < MatTable Items = " @portfolioEntryRows " Striped = " true " AllowSelection = " true " RowClass = " tester " class = " mat-elevation-z5 " ShowPaging = " false " PageSize = " 9999 " SelectionChanged = " SelectionChangedEvent " >
61
- < MatTableHeader >
62
- < th > Coin </ th >
63
- < th > Price </ th >
64
- < th > Change ( 1h )</ th >
65
- < th > Holdings </ th >
66
- </ MatTableHeader >
67
- < MatTableRow >
68
- < td > @context.symbol.ToUpper() </ td >
69
- < td > @( CurrencyUtils . Format ( context . currentPrice , activePortfolio . Currency ) ) </ td >
70
- < td style = ' color : @(context.relativeChange >= 0 ? " #17a104 " : " #FF0000 " ) ' > @context.relativeChange % </ td >
71
- <td > @context.percentage % </ td >
72
- </MatTableRow >
73
- </ MatTable >
60
+ < div style = " padding : 1 rem " >
61
+ < MatButton Label = " View " Style = " margin-right: 1rem; " OnClick = " () => ViewPortfolio(activePortfolio.Item1) " ></ MatButton >
62
+ @if ( activePortfolio . Item2 . Count > 0 )
63
+ {
64
+ @foreach ( var entry in activePortfolio . Item2 )
65
+ {
66
+ < MatButton Outlined = " true " Style = " margin-right: 1em; " Label = " @entry.Symbol.ToUpper() " OnClick = ' () => NavigationManager.NavigateTo($"/entries/{entry.Id}") ' ></ MatButton >
67
+ }
68
+ }
69
+ else
70
+ {
71
+ < MatButton Icon = " add " Outlined = " true " OnClick = " () => AddNewEntryToPortfolio(activePortfolio.Item1) " Label = " Add entry " ></ MatButton >
72
+ }
73
+ </ div >
74
+ </ MatCardContent >
75
+ </MatCard >
76
+ }
74
77
}
75
78
else
76
79
{
80
83
<div class =" mat-layout-grid-cell mat-layout-grid-cell-span-3" ></div >
81
84
</div >
82
85
</div >
83
- <MatFAB Class =" app-fab--absolute" Icon =" @MatIconNames.Add" Label =" Add a new entry " OnClick =' () => { NavigationManager.NavigateTo($"newportfolioentry/{activePortfolio.Id} "); }' ></MatFAB >
86
+ <MatFAB Class =" app-fab--absolute" Icon =" @MatIconNames.Add" Label =" Add a new portfolio " OnClick =' () => { NavigationManager.NavigateTo($"newportfolio ");}' ></MatFAB >
84
87
85
88
86
89
@code
87
90
{
88
- protected Portfolio activePortfolio ;
91
+ protected List < Tuple < Portfolio, List < PortfolioEntry > >> Portfolios ;
89
92
90
93
protected ISummaryService .Summary portfolioSummary = new (1341 m , 1 . 8 m , 9982 . 489 m , 1000 m );
91
94
120
123
121
124
protected override void OnInitialized ()
122
125
{
123
- activePortfolio = PortfolioService .GetPortfolios ()[0 ];
126
+ LoadPortfolios ();
127
+ }
128
+
129
+ private void LoadPortfolios ()
130
+ {
131
+ Portfolios = PortfolioService .GetPortfolios ().Select (
132
+ portfolio => new Tuple <Portfolio , List <PortfolioEntry >>(
133
+ portfolio ,
134
+ PortfolioEntryService .GetPortfolioEntries (portfolio .Id )
135
+ )
136
+ ).ToList ();
124
137
}
125
138
139
+
126
140
protected override async Task OnInitializedAsync ()
127
141
{
128
142
// _existingPortfolios = PortfolioService.GetPortfolios();
135
149
}
136
150
else
137
151
{
138
- NavigationManager .NavigateTo ($" entrydetail " );
152
+ NavigationManager .NavigateTo ($" entries " );
139
153
}
140
154
}
141
155
156
+ private void EditPortfolio (Portfolio activePortfolioItem1 )
157
+ {
158
+ Console .WriteLine ($" About to edit {activePortfolioItem1 .Name }" );
159
+ }
160
+
161
+ private async void DeletePortfolio (Portfolio portfolio )
162
+ {
163
+ var result = await MatDialogService .ConfirmAsync (" Do you really wish to delete this portfolio including all of it's portfolio entries and market orders?" );
164
+ if (result )
165
+ {
166
+ PortfolioService .DeletePortfolio (portfolio );
167
+ LoadPortfolios ();
168
+ StateHasChanged ();
169
+ }
170
+ }
171
+
172
+ private void AddNewEntryToPortfolio (Portfolio portfolio )
173
+ {
174
+ NavigationManager .NavigateTo ($" /newportfolioentry/{portfolio .Id }" );
175
+ }
176
+
177
+ private void ViewPortfolio (Portfolio portfolio )
178
+ {
179
+ NavigationManager .NavigateTo ($" /portfolios/{portfolio .Id }" );
180
+ }
142
181
}
0 commit comments