/// <summary> /// Action to execute when the user saves the series. /// </summary> /// <param name="window">Reference to this window.</param> public void SaveSeriesCommandAction(Window window) { //make sure all data is filled if (String.IsNullOrEmpty(Name) || String.IsNullOrEmpty(ShortName) || String.IsNullOrEmpty(RosterFull) || String.IsNullOrEmpty(NR2k3Dir)) { MessageBox.Show("Please enter all required data!", "Error Saving Series!", MessageBoxButton.OK, MessageBoxImage.Error); } else { Series series = new Series { SeriesName = Name, SeriesShort = ShortName, RosterFile = RosterFull, SeriesLogo = SeriesFull, SancLogo = SancFull, NR2K3Dir = NR2k3Dir }; try { if (selectedSeries != null) { context.Series.Remove(selectedSeries); context.Series.Add(series); context.SaveChanges(); //send the data back to the main view model. Messenger.Default.Send(new Model.AddDeleteOrModifySeriesMessage(Name)); window?.Close(); } else if (context.Series.Where(d => d.SeriesName.Equals(series.SeriesName)).Count() > 0) { MessageBox.Show("Please enter a different series name!", "Error Saving Series!", MessageBoxButton.OK, MessageBoxImage.Error); } else { context.Series.Add(series); context.SaveChanges(); //send the data back to the main view model. Messenger.Default.Send(new Model.AddDeleteOrModifySeriesMessage(Name)); window?.Close(); } } catch (DbUpdateException e) { MessageBox.Show("Error with database. Check if database file exists or is opened in another program.", "Database Error!", MessageBoxButton.OK, MessageBoxImage.Error); } } }
public void DeleteSeriesCommandAction() { if (selectedSeries != null) { string message = string.Concat("Are you sure you want to delete ", SelectedSeries, "?"); string title = string.Concat("Deleting ", selectedSeries); if (MessageBox.Show(message, title, MessageBoxButton.YesNo) == MessageBoxResult.Yes) { try { using (var db = new NR2K3ResultsEntities()) { Series s = db.Series.Where(d => d.SeriesName.Equals(SelectedSeries)).FirstOrDefault(); db.Series.Remove(s); db.SaveChanges(); } UpdateSeries(); } catch (EntityCommandExecutionException e) { MessageBox.Show("Error with database. Check if database file exists or is opened in another program.", "Database Error!", MessageBoxButton.OK, MessageBoxImage.Error); } catch (SqlException e) { MessageBox.Show("Error with database. Check if database file exists or is opened in another program.", "Database Error!", MessageBoxButton.OK, MessageBoxImage.Error); } SelectedSeries = (Series.Count > 0) ? Series.ElementAt(0) : null; } } }