public static List<Book> BooksListBySeries(Series series, Book current = null) { using (var db = new BookshelfDbContext()) { return db.Books .Where(x => x.Series.Id == series.Id && (current == null || x.Id != current.Id)) .OrderBy(x => x.Name) .ToList(); } }
public static Series AddSeries(Series series) { if (series == null) return null; using (var db = new BookshelfDbContext()) { db.Series.Add(series); db.SaveChanges(); var id = db.Series.Max(x => x.Id); return db.Series.Where(x => x.Id == id).FirstOrDefault(); } }
private void AddSeries(object sedner) { var dlg = new AddValueWindow(AddNewSeriesLabelText); if (dlg.ShowDialog() == false) return; var value = dlg.GetValue(); if (value == null || value == string.Empty) return; if (!SeriesList.Where(x => x.Name == value).Any()) { var series = new Series(); series.Name = value; using (var db = new BookshelfDbContext()) { db.Series.Add(series); db.SaveChanges(); } OnPropertyChanged("SeriesList"); } var tSeries = SeriesList.Where(x => x.Name == value).First(); if (tSeries != null) SeriesID = tSeries.Id; }