Esempio n. 1
0
 public BookInfo(int? BookId = null)
 {
   if (BookId != null)
   {
     using (var db = new BookshelfDbContext())
     {
       Book = db.Books.Where(x => x.Id == BookId).FirstOrDefault();
     }
   }
 }
Esempio n. 2
0
 public static List<Book> BooksListByAuthor(Author author)
 {
   using (var db = new BookshelfDbContext())
   {
     return db.Books
       .Where(x => x.Author.Id == author.Id)
       .OrderBy(x => x.Name)
       .ToList();
   }
 }
Esempio n. 3
0
 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();
   }
 }
Esempio n. 4
0
 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();
   }
 }
Esempio n. 5
0
 public static Author AddAuthor(Author author)
 {
   if (author == null) return null;
   using (var db = new BookshelfDbContext())
   {
     db.Authors.Add(author);
     db.SaveChanges();
     var id = db.Authors.Max(x => x.Id);
     return db.Authors.Where(x => x.Id == id).FirstOrDefault();
   }
 }
Esempio n. 6
0
 public static Country AddCountry(Country country)
 {
   if (country == null) return null;
   using (var db = new BookshelfDbContext())
   {
     db.Countries.Add(country);
     db.SaveChanges();
     var id = db.Countries.Max(x => x.Id);
     return db.Countries.Where(x => x.Id == id).FirstOrDefault();
   }
 }
Esempio n. 7
0
 public static Publisher AddPublisher(Publisher publisher)
 {
   if (publisher == null) return null;
   using (var db = new BookshelfDbContext())
   {
     db.Publishers.Add(publisher);
     db.SaveChanges();
     var id = db.Publishers.Max(x => x.Id);
     return db.Publishers.Where(x => x.Id == id).FirstOrDefault();
   }
 }
Esempio n. 8
0
 public static Language AddLanguage(Language language)
 {
   if (language == null) return null;
   using (var db = new BookshelfDbContext())
   {
     db.Languages.Add(language);
     db.SaveChanges();
     var id = db.Languages.Max(x => x.Id);
     return db.Languages.Where(x => x.Id == id).FirstOrDefault();
   }
 }
Esempio n. 9
0
 public bool Save()
 {
   if (Book.Name == string.Empty)
     return false;
   using (var db = new BookshelfDbContext())
   {
     if (db.Books.Where(x => x.Id == Book.Id).Any())
     {
       var ExistingBook = db.Books.Where(x => x.Id == Book.Id).First();
       foreach (var item in typeof(Book).GetProperties())
       {
         if (item.GetValue(Book) != item.GetValue(ExistingBook))
         {
           db.Books.Attach(Book);
           db.Entry(Book).State = EntityState.Modified;
         }
       }          
     }
     else
       db.Books.Add(Book);
     db.SaveChanges();
   }
   return true;
 }
Esempio n. 10
0
 private Publisher AddPublisherCommon()
 {
   var dlg = new AddValueWindow(AddNewPublisherLabelText);
   if (dlg.ShowDialog() == false) return null;
   var value = dlg.GetValue();
   if (value == null || value == string.Empty) return null;
   if (!PublisherList.Where(x => x.Name == value).Any())
   {
     var Publisher = new Publisher();
     Publisher.Name = value;
     using (var db = new BookshelfDbContext())
     {
       db.Publishers.Add(Publisher);
       db.SaveChanges();
     }
     OnPropertyChanged("PublisherList");
   }
   return PublisherList.Where(x => x.Name == value).First();
 }
Esempio n. 11
0
 private Country AddCountryCommon()
 {
   var dlg = new AddValueWindow(AddNewCountryLabelText);
   if (dlg.ShowDialog() == false) return null;
   var value = dlg.GetValue();
   if (value == null || value == string.Empty) return null;
   if (!CountryList.Where(x => x.Name == value).Any())
   {
     var country = new Country();
     country.Name = value;
     using (var db = new BookshelfDbContext())
     {
       db.Countries.Add(country);
       db.SaveChanges();
     }
     OnPropertyChanged("CountryList");
   }
   return CountryList.Where(x => x.Name == value).First();
 }
Esempio n. 12
0
 private Language AddLanguageCommon()
 {
   var dlg = new AddValueWindow(AddNewLanguageLabelText);
   if (dlg.ShowDialog() == false) return null;
   var value = dlg.GetValue();
   if (value == null || value == string.Empty) return null;
   if (!LanguageList.Where(x => x.Name == value).Any())
   {
     var language = new Language();
     language.Name = value;
     using (var db = new BookshelfDbContext())
     {
       db.Languages.Add(language);
       db.SaveChanges();
     }
     OnPropertyChanged("LanguageList");
   }
   return LanguageList.Where(x => x.Name == value).First();
 }
Esempio n. 13
0
 private void AddType(object sender)
 {
   var dlg = new AddValueWindow(AddNewTypeLabelText);
   if (dlg.ShowDialog() == false) return;
   var value = dlg.GetValue();
   if (value == null || value == string.Empty) return;
   if (!TypeList.Where(x => x.Name == value).Any())
   {
     var type = new DB.Type();
     type.Name = value;
     using (var db = new BookshelfDbContext())
     {
       db.Types.Add(type);
       db.SaveChanges();
     }
     OnPropertyChanged("TypeList");
   }
   var tType = TypeList.Where(x => x.Name == value).First();
   if (tType != null)
     TypeID = tType.Id;
 }
Esempio n. 14
0
 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;
 }
Esempio n. 15
0
 private void AddAuthor(object sender)
 {
   var dlg = new AddValueWindow(AddNewAuthorLabelText);
   if (dlg.ShowDialog() == false) return;
   var value = dlg.GetValue();
   if (value == null || value == string.Empty) return;
   if (!AuthorList.Where(x => x.Name == value).Any())
   {
     var author = new Author();
     author.Name = value;
     using (var db = new BookshelfDbContext())
     {
       db.Authors.Add(author);
       db.SaveChanges();
     }
     OnPropertyChanged("AuthorList");
   }
   var tAuthor = AuthorList.Where(x => x.Name == value).First();
   if (tAuthor != null)
     AuthorID = tAuthor.Id;
 }