private List <BookModel> GetAllBooks() { using (LaybraryTestContext db = new LaybraryTestContext()) { List <BookModel> listModel = new List <BookModel>(); var model = db.Books.OrderBy(b => b.Queue).ToList(); foreach (var item in model) { listModel.Add(new BookModel { Id = item.Id, Title = item.Title, Author = item.Author, Registration_Date = item.Registration_Date, Translation = item.Translation, Note = item.Note, Registration_Order = item.Registration_Order, Queue = item.Queue, Series_Id = item.Series_Id, Status_Id = item.Status_Id, Genre_Id = item.Genre_Id, Source_Id = item.Source_Id }); } return(listModel); } }
private List <BookStatu> GetAllStatus() { using (LaybraryTestContext db = new LaybraryTestContext()) { return(db.BookStatus.ToList()); } }
private BookStatu GetBookStatus(string status) { using (LaybraryTestContext db = new LaybraryTestContext()) { return(db.BookStatus.Where(bs => bs.Status == status).First()); } }
private void AddNewBookSources(BookSource bookSources) { using (LaybraryTestContext db = new LaybraryTestContext()) { db.BookSources.Add(bookSources); db.SaveChanges(); } }
private void AddNewBookSerieStatus(BookSeriesStatu bookSerieStatus) { using (LaybraryTestContext db = new LaybraryTestContext()) { db.BookSeriesStatus.Add(bookSerieStatus); db.SaveChanges(); } }
private void AddNewBookGenre(BookGenre bookGenre) { using (LaybraryTestContext db = new LaybraryTestContext()) { db.BookGenres.Add(bookGenre); db.SaveChanges(); } }
private int GetBookSerieStatusId(string description) { using (LaybraryTestContext db = new LaybraryTestContext()) { var model = db.BookSeriesStatus.SingleOrDefault(bss => bss.Description == description); if (model != null) { return(model.Id); } else { return(0); } } }
private List <BookSeriesStatusModel> GetAllSeriesStatus() { using (LaybraryTestContext db = new LaybraryTestContext()) { List <BookSeriesStatusModel> listModel = new List <BookSeriesStatusModel>(); var model = db.BookSeriesStatus.ToList(); foreach (var item in model) { listModel.Add(new BookSeriesStatusModel { Id = item.Id, Description = item.Description }); } return(listModel); } }
private int GetBookGenreId(string description) { using (LaybraryTestContext db = new LaybraryTestContext()) { var model = db.BookGenres.SingleOrDefault(g => g.Description == description); if (model != null) { return(model.Id); } else { return(0); } } }
private int GetBookNextOnTheQueue() { using (LaybraryTestContext db = new LaybraryTestContext()) { var lastQueue = db.Books.OrderByDescending(b => b.Queue).Select(b => b.Queue).First(); if (lastQueue != null) { return((int)lastQueue + 1); } else { return(1); } } }
private List <BookGenreModel> GetAllGenres() { using (LaybraryTestContext db = new LaybraryTestContext()) { List <BookGenreModel> listModel = new List <BookGenreModel>(); var model = db.BookGenres.OrderBy(g => g.Description).ToList(); foreach (var item in model) { listModel.Add(new BookGenreModel { Id = item.Id, Description = item.Description }); } return(listModel); } }
private int GetBookNextOrder() { using (LaybraryTestContext db = new LaybraryTestContext()) { var lastOrder = db.Books.OrderByDescending(b => b.Registration_Order).Select(b => b.Registration_Order).First(); if (lastOrder != null) { return((int)lastOrder + 1); } else { return(1); } } }
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 List <ReadingHistoryModel> GetBookHistory(int bookId) { using (LaybraryTestContext db = new LaybraryTestContext()) { List <ReadingHistoryModel> listModel = new List <ReadingHistoryModel>(); var model = db.ReadingHistories.Where(h => h.Book_Id == bookId).OrderByDescending(h => h.Id).ToList(); foreach (var item in model) { listModel.Add(new ReadingHistoryModel { Id = item.Id, Book_Id = item.Book_Id, Start_Date = item.Start_Date, End_Date = item.End_Date }); } return(listModel); } }
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(); } }
private List <BookModel> SearchBooks(string _title, string _author, DateTime?_registrationDate, string _translation, string _note, int _statusId, int _genreId, int _sourceId) { using (LaybraryTestContext db = new LaybraryTestContext()) { List <BookModel> listModel = new List <BookModel>(); IQueryable <Book> result = db.Books; if (!String.IsNullOrEmpty(_title)) { result = result.Where(b => b.Title.Contains(_title)); } if (!String.IsNullOrEmpty(_author)) { result = result.Where(b => b.Author.Contains(_author)); } if (_registrationDate != null) { result = result.Where(b => b.Registration_Date.HasValue == true && _registrationDate.HasValue == true && b.Registration_Date.Value.Day == _registrationDate.Value.Day && b.Registration_Date.Value.Month == _registrationDate.Value.Month && b.Registration_Date.Value.Year == _registrationDate.Value.Year); } if (!String.IsNullOrEmpty(_translation)) { result = result.Where(b => b.Translation.Contains(_translation)); } if (!String.IsNullOrEmpty(_note)) { result = result.Where(b => b.Note.Contains(_note)); } if (_statusId != 0) { result = result.Where(b => b.Status_Id == _statusId); } if (_genreId != 0) { result = result.Where(b => b.Genre_Id == _genreId); } if (_sourceId != 0) { result = result.Where(b => b.Source_Id == _sourceId); } var model = result.OrderBy(b => b.Registration_Order).ToList(); foreach (var item in model) { listModel.Add(new BookModel { Id = item.Id, Title = item.Title, Author = item.Author, Registration_Date = item.Registration_Date, Translation = item.Translation, Note = item.Note, Registration_Order = item.Registration_Order, Queue = item.Queue, Series_Id = item.Series_Id, Status_Id = item.Status_Id, Genre_Id = item.Genre_Id, Source_Id = item.Source_Id }); } return(listModel); } }