public ActionResult Create(BookItemViewModel bookItem, HttpPostedFileBase cover, HttpPostedFileBase tableOfContents) { if (ModelState.IsValid) { if (!db.BookItems.Any(b => b.ISBN == bookItem.ISBN)) { vt.CreateBookItem(bookItem, db, cover, tableOfContents); return(RedirectToAction("Index")); } else { ViewBag.Error = true; ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "Name"); ViewBag.Authors = new SelectList(vt.GetAuthorsFromDb(db), "Value", "Text"); ViewBag.Labels = new SelectList(db.Labels, "LabelID", "Name"); return(View(bookItem)); } } ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "Name"); ViewBag.Authors = new SelectList(vt.GetAuthorsFromDb(db), "Value", "Text"); ViewBag.Labels = new SelectList(db.Labels, "LabelID", "Name"); return(View(bookItem)); }
public BookItemViewModel GetBookViewModel(BookItem book, ApplicationDbContext db) { BookItemViewModel bookView = new BookItemViewModel(); bookView.ID = book.BookItemID; bookView.Title = book.Title; bookView.ISBN = book.ISBN; bookView.Publisher = book.Publisher; bookView.ReleaseDate = book.ReleaseDate; bookView.Descryption = book.Descryption; if (book.Category != null) { bookView.Category = db.Categories.Single(c => c.CategoryID == book.Category.CategoryID); bookView.CategoryID = book.Category.CategoryID; } bookView.Authors = db.Authors.Where(a => a.AuthorGroups.Any(g => g.BookItem.BookItemID == book.BookItemID)).ToList(); bookView.Labels = db.Labels.Where(a => a.LabelGroups.Any(g => g.BookItem.BookItemID == book.BookItemID)).ToList(); bookView.Number = book.Number; bookView.SelectedLabels = bookView.Labels.Select(x => x.LabelID).ToList(); bookView.SelectedAuthors = bookView.Authors.Select(x => x.AuthorID).ToList(); bookView.AvailableNumber = book.Number - db.Orders.Count(o => o.BookItemID == book.BookItemID && o.Returned); return(bookView); }
public void CreateBookItem(BookItemViewModel bookView, ApplicationDbContext db, HttpPostedFileBase cover, HttpPostedFileBase tableOfContents) { BookItem bookItem = new BookItem() { Title = bookView.Title, ISBN = bookView.ISBN, Descryption = bookView.Descryption, Publisher = bookView.Publisher, ReleaseDate = bookView.ReleaseDate, Category = db.Categories.Find(bookView.CategoryID), Number = bookView.Number, AddDate = DateTime.Now }; db.Set <BookItem>().AddOrUpdate(bookItem); db.SaveChanges(); var book = db.BookItems.FirstOrDefault(x => x.ISBN == bookItem.ISBN); db.Categories.Find(bookView.CategoryID).BookItem.Add(book); foreach (var authorId in bookView.SelectedAuthors) { var author = db.Authors.Single(a => a.AuthorID == authorId); var ag = new AuthorGroup() { Author = author, BookItem = book }; db.Set <AuthorGroup>().AddOrUpdate(ag); } db.SaveChanges(); foreach (var labelId in bookView.SelectedLabels) { var label = db.Labels.Single(l => l.LabelID == labelId); var labelgroup = new LabelGroup() { Label = label, BookItem = book, }; db.Set <LabelGroup>().AddOrUpdate(labelgroup); } db.SaveChanges(); if (cover != null) { AddAttachments_displayable(db, bookItem.BookItemID, cover, FileType.Cover); } if (tableOfContents != null) { AddAttachments_displayable(db, bookItem.BookItemID, tableOfContents, FileType.TableOfContents); } foreach (var file in bookView.FileList) { AddAttachments(db, bookItem.BookItemID, file, FileType.Attachment); } }
public async Task <IActionResult> Index() { var vm = new BooksViewModel(); var allBooks = await _bookService.ReadAllAsync(); var allCategories = await _categoryService.ReadAllAsync(); var allCategoryAreas = await _categoryAreaService.ReadAllAsync(); foreach (var area in allCategoryAreas.OrderBy(ca => ca.Name)) { var areaVm = new CategoryAreaItemViewModel { Id = area.Id, Name = area.Name, Ref = $"area-{area.Id}" }; var categories = allCategories.Where(c => c.CategoryArea?.Id == area.Id) .OrderBy(c => c.Name) .ToList(); foreach (var category in categories) { var categoryVm = new CategoryItemViewModel { Id = category.Id, Name = category.Name, Ref = $"category-{category.Id}" }; var books = allBooks.Where(b => b.Category?.Id == category.Id) .OrderByDescending(b => b.PublishYear) .ThenBy(b => b.Name) .ToList(); foreach (var book in books) { var bookVm = new BookItemViewModel { Id = book.Id, Title = book.Name, Year = book.PublishYear, Authors = book.Authors, Rating = book.Rating, ImageUrl = book.ImageUri, AmazonUrl = book.AmazonUri, DownloadUrl = book.ContentUri, Reflection = book.Reflection }; categoryVm.Books.Add(bookVm); } areaVm.Categories.Add(categoryVm); } vm.CategoryAreas.Add(areaVm); } return(View(vm)); }
public List <BookItemViewModel> GetInstalledBooksFiles() { string[] books = Directory.GetFiles(Path.Combine(VTrainerModule.Default.RootPath, VTrainerModule.Default.BookPath), "*.vbook"); List <BookItemViewModel> retval = new List <BookItemViewModel>(); foreach (string book in books) { BookItemViewModel vm = new BookItemViewModel(); vm.FileName = Path.GetFileName(book); vm.FilePath = book; vm.ImageFilePath = book + ".png"; retval.Add(vm); } return(retval); }
public BookItemViewModel GetBookInfo(int id) { BookItemViewModel model = null; var book = _bookRepository.GetBookById(id); if (book != null) { model = new BookItemViewModel { Id = book.Id, Title = book.Title, Pages = book.Pages, Author = book.Author.LastName }; } return(model); }
public JsonResult InserBook(BookItemViewModel bookViewModel, int numberofInstances) { var bookMetadata = this.bookMetadataService.GetAllBookMetadatasByName(bookViewModel.BookMetaDataModel.Author); var bookModel = new BookModel(); if (bookMetadata != null) { bookModel = this.viewmodelTransalator.TransalateToModel(bookViewModel); } //if the book is been entered in the library for the first time, hence has no book metadata stored else { this.bookMetadataService.Insert(bookMetadata); } bookService.Insert(bookModel); return(null); }
public ActionResult Edit(BookItemViewModel bookItemViewModel) { try { Book book = _dbContext.Books.Find(bookItemViewModel.selectedBook); StateType state = _dbContext.StateTypes.Find(bookItemViewModel.selectedState); BookItem bookItem = new BookItem { ID = bookItemViewModel.ID, Book = book, State = state }; _dbContext.BookItems.Update(bookItem); _dbContext.SaveChanges(); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public async Task <IActionResult> Create(BookItemViewModel bookItemViewModel) { try { Book book = _dbContext.Books.Find(bookItemViewModel.selectedBook); StateType state = _dbContext.StateTypes.Find(bookItemViewModel.selectedState); BookItem bookItem = new BookItem { ID = bookItemViewModel.ID, State = state, Book = book }; _dbContext.BookItems.Add(bookItem); await _dbContext.SaveChangesAsync(); return(RedirectToPage("/Index")); } catch { return(View()); } }
public ActionResult Delete(BookItemViewModel bookDel) { _bookProvider.Delete(bookDel.Id); return(RedirectToAction("Index")); }
public void ReturnItem(BookItemViewModel bookViewModel, string userEmailId) { this.lendingService.ReturnBorrowedItem(bookViewModel.Id, userEmailId); }