private async void EditButton_Click(object sender, RoutedEventArgs e) { if (sender is Button button && button.Tag != null) { var editWindow = EditPanel; //editWindow.Width = 700; //editWindow.Height = 650; var content = new SessionEditControl(); editWindow.Title = "Edit Session"; if (content.DataContext is SessionViewModel editVM && button.Tag is SessionViewModel sessionVM) { if (sessionVM.SessionType == Enums.SessionType.Race) { editVM.UpdateSource(Models.Sessions.RaceSessionModel.GetTemplate()); } editVM.Model.CopyFrom(sessionVM.Model); editVM.Schedule = sessionVM.Schedule; editWindow.ModalContent = content; if (editWindow.ShowDialog() == true) { sessionVM.Model.CopyFrom(editVM.Model); await sessionVM.SaveChanges(); } } } }
private async void AddButton_Click(object sender, RoutedEventArgs e) { if (sender is Button button) { var editWindow = new ModalOkCancelControl(); try { //editWindow.Width = 700; //editWindow.Height = 650; editWindow.Title = "Add New Session"; var content = new SessionEditControl(); var Schedule = button.DataContext as ScheduleViewModel; MainGrid.Children.Add(editWindow); if (content.DataContext is SessionViewModel editVM && Schedule != null) { editVM.Schedule = Schedule; editWindow.ModalContent = content; if (editWindow.ShowDialog() == true) { await Schedule.AddSessionAsync(editVM.Model); } } } finally { MainGrid.Children.Remove(editWindow); } } }
private async Task EditSessionDialog(SessionViewModel sessionVM) { if (sessionVM == null) { return; } var editWindow = new ModalOkCancelControl(); try { //editWindow.Width = 700; //editWindow.Height = 650; var content = new SessionEditControl(); MainGrid.Children.Add(editWindow); editWindow.Title = "Edit Session"; var editVM = content.DataContext as SessionViewModel; if (sessionVM.SessionType == Enums.SessionType.Race) { editVM.UpdateSource(Models.Sessions.RaceSessionModel.GetTemplate()); } editVM.Model.CopyFrom(sessionVM.Model); editVM.Schedule = sessionVM.Schedule; editWindow.ModalContent = content; if (editWindow.ShowDialog() == true) { sessionVM.Model.CopyFrom(editVM.Model); await sessionVM.SaveChanges(); } } finally { MainGrid.Children.Remove(editWindow); } }