@@ -83,6 +83,7 @@ public bool CheckVisible
8383 }
8484
8585
86+ public ICommand ClearEntryCommand { get ; set ; }
8687 public ICommand CopyEntryCommand { get ; set ; }
8788 public ICommand NewPositionCommand { get ; }
8889 public ICommand RemovePositionCommand { get ; }
@@ -115,11 +116,12 @@ public MainWindowViewModel()
115116
116117 CopyEntryCommand = ReactiveCommand . Create ( ( ) => CopyEntry ( ) ) ;
117118 NewPositionCommand = ReactiveCommand . Create ( ( ) => CreateNewPosition ( ) ) ;
118- NewEntryCommand = ReactiveCommand . Create ( ( ) => SaveEntry ( ) ) ;
119- SaveCommand = ReactiveCommand . Create ( ( ) => Save ( ) ) ;
120- ExportToCsvCommand = ReactiveCommand . Create ( async ( ) => await ExportToCsv ( ) ) ;
121- CheckDbConnectionCommand = ReactiveCommand . Create ( async ( ) => await CheckDbConnection ( ) ) ;
122-
119+ NewEntryCommand = ReactiveCommand . Create ( ( ) => AddEntry ( ) ) ;
120+ SaveCommand = ReactiveCommand . Create ( ( ) => SavePositionsWithEntries ( ) ) ;
121+ ExportToCsvCommand = ReactiveCommand . Create ( ( ) => ExportToCsv ( ) ) ;
122+ CheckDbConnectionCommand = ReactiveCommand . Create ( ( ) => CheckDbConnection ( ) ) ;
123+ ClearEntryCommand = ReactiveCommand . Create ( ( ) => ClearEntry ( ) ) ;
124+
123125 LoadPositionsWithEntries ( ) ;
124126 }
125127
@@ -194,7 +196,7 @@ private void CreateNewPosition()
194196 CrossVisible = true ;
195197 }
196198
197- private void SaveEntry ( )
199+ private void AddEntry ( )
198200 {
199201 int entryId = Logic . SaveEntry ( CurrentEntry . VmToModel ( ) ) ;
200202 EntryViewModel entryWithId = CurrentEntry ;
@@ -236,8 +238,12 @@ private async Task RemovePosition()
236238
237239 private async Task RemoveEntry ( )
238240 {
239- if ( CurrentEntry == null ! || CurrentEntry . Id == 0 )
241+ if ( CurrentEntry == null || CurrentEntry . Id == 0 )
242+ {
243+ if ( CurrentPosition . Entries . Contains ( CurrentEntry ) )
244+ CurrentPosition . Entries . Remove ( CurrentEntry ) ;
240245 return ;
246+ }
241247
242248 MainUiActive = false ;
243249
@@ -259,7 +265,7 @@ private async Task RemoveEntry()
259265 MainUiActive = true ;
260266 }
261267
262- private void Save ( )
268+ private void SavePositionsWithEntries ( )
263269 {
264270 Logic . SavePosition ( CurrentPosition . VmToModel ( ) ) ;
265271
@@ -315,6 +321,11 @@ private void CopyEntry()
315321 CrossVisible = true ;
316322 CheckVisible = false ;
317323 }
324+
325+ private void ClearEntry ( )
326+ {
327+ CurrentEntry = new EntryViewModel ( ) ;
328+ }
318329
319330
320331 private string GetConnectionErrorMessage ( )
0 commit comments