private async void EditTermOnClick(object obj) { var term = SelectedTerm; DateTime startDate, endDate; if (term.Period != null) { startDate = term.Period.StartDate; endDate = term.Period.EndDate; } else { startDate = DateTime.Today; endDate = DateTime.Today; } var dialogViewModel = new CreateOrEditTermDialogViewModel(term.Name, term.IsActive, startDate, endDate); if (dialogViewModel.ShowDialog() == true) { try { if (dialogViewModel.TermIsActive) { term.SetActive(new Period(dialogViewModel.SelectedStartDate, dialogViewModel.SelectedEndDate)); } else { term.SetPassive(); } await _termService.UpdateTermAsync(term); } catch (InvalidOperationException e) { MessageBox.Show(e.Message, Strings.TermDialog_Title_EditTerm, MessageBoxButton.OK); } SelectedTermIndex = -1; } }
private async void NewTermOnClick(object obj) { var termName = (Terms.Count + 1).ToString(); var dialogViewModel = new CreateOrEditTermDialogViewModel(termName); if (dialogViewModel.ShowDialog() == true) { try { var term = new Term(dialogViewModel.TermName, dialogViewModel.TermIsActive, new Period(dialogViewModel.SelectedStartDate, dialogViewModel.SelectedEndDate)); Terms.Add(term); await _termService.AddTermAsync(term); } catch (InvalidOperationException e) { MessageBox.Show(e.Message, Strings.TermDialog_Title_CreateTerm, MessageBoxButton.OK); } } }