private void AddNewBookGenre(BookGenre bookGenre) { using (LaybraryTestContext db = new LaybraryTestContext()) { db.BookGenres.Add(bookGenre); db.SaveChanges(); } }
private void AddNewBookSerieStatus(BookSeriesStatu bookSerieStatus) { using (LaybraryTestContext db = new LaybraryTestContext()) { db.BookSeriesStatus.Add(bookSerieStatus); db.SaveChanges(); } }
private void AddNewBookSources(BookSource bookSources) { using (LaybraryTestContext db = new LaybraryTestContext()) { db.BookSources.Add(bookSources); db.SaveChanges(); } }
private void ReorderQueue(Book book) { if (book.Id == 0) { using (LaybraryTestContext db = new LaybraryTestContext()) { var booksToReorder = db.Books.Where(b => b.Queue >= book.Queue).ToList(); if (booksToReorder != null) { foreach (var item in booksToReorder) { item.Queue = item.Queue + 1; db.SaveChanges(); } } } } else { using (LaybraryTestContext db = new LaybraryTestContext()) { var booksToReorderAfterNewIndex = db.Books.Where(b => b.Queue >= book.Queue).ToList(); if (booksToReorderAfterNewIndex != null) { foreach (var item in booksToReorderAfterNewIndex) { item.Queue = item.Queue + 1; db.SaveChanges(); } } var booksToReorderBeforeNewIndex = db.Books.Where(b => b.Queue < book.Queue).ToList(); if (booksToReorderBeforeNewIndex != null) { foreach (var item in booksToReorderBeforeNewIndex) { item.Queue = item.Queue - 1; db.SaveChanges(); } } } } }
private void Reorder(Book book) { if (book.Id == 0) { using (LaybraryTestContext db = new LaybraryTestContext()) { var booksToReorder = db.Books.Where(b => b.Registration_Order >= book.Registration_Order).ToList(); if (booksToReorder != null) { foreach (var item in booksToReorder) { item.Registration_Order = item.Registration_Order + 1; db.SaveChanges(); } } } } else { using (LaybraryTestContext db = new LaybraryTestContext()) { var booksToReorderAfterNewIndex = db.Books.Where(b => b.Registration_Order >= book.Registration_Order).ToList(); if (booksToReorderAfterNewIndex != null) { foreach (var item in booksToReorderAfterNewIndex) { item.Registration_Order = item.Registration_Order + 1; db.SaveChanges(); } } var booksToReorderBeforeNewIndex = db.Books.Where(b => b.Registration_Order < book.Registration_Order).ToList(); if (booksToReorderBeforeNewIndex != null) { foreach (var item in booksToReorderBeforeNewIndex) { item.Registration_Order = item.Registration_Order - 1; db.SaveChanges(); } } } } }
private bool DeleteBookSerieStatus(string description) { int Id = GetBookSerieStatusId(description); if (Id != 0) { using (LaybraryTestContext db = new LaybraryTestContext()) { var model = db.BookSeriesStatus.SingleOrDefault(bss => bss.Id == Id); db.BookSeriesStatus.Remove(model); db.SaveChanges(); return(true); } } else { return(false); } }
private void UpdateBookHistory(ReadingHistory readingHist) { using (LaybraryTestContext db = new LaybraryTestContext()) { if (readingHist.Id != 0) { var model = db.ReadingHistories.SingleOrDefault(h => h.Id == readingHist.Id); if (model != null) { model.Start_Date = readingHist.Start_Date; model.End_Date = readingHist.End_Date; model.Book_Id = readingHist.Book_Id; } } else { db.ReadingHistories.Add(readingHist); } db.SaveChanges(); } }
private void UpdateBook(Book book) { using (LaybraryTestContext db = new LaybraryTestContext()) { if (book.Id == 0) { db.Books.Add(book); } else { var bookInDb = db.Books.Single(b => b.Id == book.Id); if (!String.IsNullOrEmpty(book.Title)) { bookInDb.Title = book.Title; } else { book.Title = bookInDb.Title; } if (!String.IsNullOrEmpty(book.Author)) { bookInDb.Author = book.Author; } else { book.Author = bookInDb.Author; } if (book.Registration_Date != null) { bookInDb.Registration_Date = book.Registration_Date; } else { book.Registration_Date = bookInDb.Registration_Date; } if (!String.IsNullOrEmpty(book.Translation)) { bookInDb.Translation = book.Translation; } else { book.Translation = bookInDb.Translation; } if (!String.IsNullOrEmpty(book.Note)) { bookInDb.Note = book.Note; } else { book.Note = bookInDb.Note; } if (book.Registration_Order != null) { bookInDb.Registration_Order = book.Registration_Order; } else { book.Registration_Order = bookInDb.Registration_Order; } if (book.Queue != null) { bookInDb.Queue = book.Queue; } else { book.Queue = bookInDb.Queue; } if (book.Series_Id != null) { bookInDb.Series_Id = book.Series_Id; } else { book.Series_Id = bookInDb.Series_Id; } if (book.Status_Id != null) { bookInDb.Status_Id = book.Status_Id; } else { book.Status_Id = bookInDb.Status_Id; } if (book.Source_Id != null) { bookInDb.Source_Id = book.Source_Id; } else { book.Source_Id = bookInDb.Source_Id; } } db.SaveChanges(); } }