public ActionResult Edit(Models.BookModel bmodel) { book.UpdateData(bmodel); var dataList = book.DisplayData(); return(View("Index", dataList)); }
public ActionResult AddData(Models.BookModel books) { book.SaveData(books); var data = book.DisplayData(); return(View("Index", data)); }
public IActionResult ViewBook(string ISBN) { logic = new SearchBook(_configuration); Models.BookModel book = logic.ReturnBook(ISBN); return(View("ViewBook", book)); }
public BooksCategoryBooksViewModel GetBooksCategoryBooks(Guid booksCatID) { BooksCategoryBooksViewModel booksCategoryBooksViewModel = new BooksCategoryBooksViewModel(); BooksCategory booksCategory = booksLibraryDataContext.BooksCategories.FirstOrDefault(x => x.IDBooksCategory == booksCatID); if (booksCategory != null) { booksCategoryBooksViewModel.Genre = booksCategory.Genre; booksCategoryBooksViewModel.ChildAppropriate = booksCategory.ChildAppropriate; IQueryable <Book> catBooks = booksLibraryDataContext.Books.Where(x => x.IDBooksCategory == booksCatID); foreach (Book dbBook in catBooks) { Models.BookModel bookModel = new Models.BookModel(); bookModel.Name = dbBook.Name; bookModel.Author = dbBook.Author; bookModel.Publisher = dbBook.Publisher; bookModel.NumberOfCopies = dbBook.NumberOfCopies; bookModel.imageUrl = dbBook.imageUrl; booksCategoryBooksViewModel.Books.Add(bookModel); } } return(booksCategoryBooksViewModel); }
public void RemoveBook(Models.BookModel search) { var id = HttpContext.User.FindFirst("id"); if (id == null) { throw new Exceptions.AuthorizationException("Ошибка аутентификации, отсутствуют дополнительные параметры пользователя"); } using (BookDb.BookDbContext db = new BookDb.BookDbContext()) { using (var scope = db.Database.BeginTransaction()) { var lnk = db.LnkUserBook.Find(search.lnkId.Value); if (lnk == null) { throw new Exceptions.GeneralException("Связка не найдена"); } db.LnkUserBook.Remove(lnk); db.SaveChanges(); scope.Commit(); } } }
public LocationInLibraryBooksViewModel GetLocationInLibraryBooks(Guid locationInLibraryID) { LocationInLibraryBooksViewModel locationInLibraryBooksViewModel = new LocationInLibraryBooksViewModel(); LocationInLibrary locationInLibrary = booksLibraryDataContext.LocationInLibraries.FirstOrDefault(x => x.IDLocationInLibrary == locationInLibraryID); if (locationInLibrary != null) { locationInLibraryBooksViewModel.Name = locationInLibrary.Name; locationInLibraryBooksViewModel.Floor = locationInLibrary.Floor; locationInLibraryBooksViewModel.Sector = locationInLibrary.Sector; locationInLibraryBooksViewModel.Shelf = locationInLibrary.Shelf; IQueryable <Book> locationInLibraryBooks = booksLibraryDataContext.Books.Where(x => x.IDLocationInLibrary == locationInLibraryID); foreach (Book dbBook in locationInLibraryBooks) { Models.BookModel bookModel = new Models.BookModel(); bookModel.Name = dbBook.Name; bookModel.Author = dbBook.Author; bookModel.Publisher = dbBook.Publisher; bookModel.NumberOfCopies = dbBook.NumberOfCopies; locationInLibraryBooksViewModel.Books.Add(bookModel); } } return(locationInLibraryBooksViewModel); }
public ActionResult DownloadBook(Models.BookModel book) { string file = "~/App_Data/" + book.DlLink; string contentType = "application/pdf"; return(File(file, contentType, Path.GetFileName(file))); }
public IEnumerable <Models.BookModel> MyBookList(Models.BookModel search) { var id = HttpContext.User.FindFirst("id"); if (id == null) { throw new Exceptions.AuthorizationException("Ошибка аутентификации, отсутствуют дополнительные параметры пользователя"); } return(GetBookList(int.Parse(id.Value), search.bookName, false)); }
public void SaveData(Models.BookModel bookModel) { var data = new Book() { BookID = bookModel.BookID, BookName = bookModel.BookName, BookCategoryID = bookModel.BookCategoryID, AuthorID = bookModel.AuthorID, SubjectID = bookModel.SubjectID, Remarks = bookModel.Remarks }; context.Books.Add(data); context.SaveChanges(); }
public ActionResult Edit(Guid id, FormCollection collection) { try { // TODO: Add update logic here Models.BookModel bookModel = new Models.BookModel(); UpdateModel(bookModel); bookRepository.UpdateBook(bookModel); return(RedirectToAction("Index")); } catch { return(View("EditBook")); } }
public async Task <IHttpActionResult> Post([FromBody] Models.BookModel book) { // We can even use Fluent validation here for better validation, but for demo app, simple model validation will work. if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Convert DTO to Entity. Book entity = Mapper.Map <Book>(book); // Save entity in db, can also check GUID is unique or not, because GUID is not cryptographically unique, for now it is fine. _bookRepository.Insert(entity); await _unitOfWork.SaveChangesAsync(); // If we comes here, means Success return(Created($"/books/{entity.BookId}", Mapper.Map <BookDTO>(entity))); }
public void UpdateData(Models.BookModel model) { try { Book data = new Book(); data = context.Books. Where(a => a.BookID == model.BookID).FirstOrDefault(); data.BookName = model.BookName; data.BookCategoryID = model.BookCategoryID; data.AuthorID = model.AuthorID; data.SubjectID = model.SubjectID; data.Remarks = model.Remarks; context.SaveChanges(); } catch (Exception) { throw; } }
public ActionResult Create(FormCollection collection) { try { // TODO: Add insert logic here BookModel bookModel = new Models.BookModel(); UpdateModel(bookModel); bookRepository.InsertBook(bookModel); var bookCategories = booksCategoryRepository.GetAllBookCategories(); SelectList lst = new SelectList(bookCategories, "IDBooksCategory", "Genre"); Session["bookCategory"] = lst; var locationsInLibrary = locationInLibraryRepository.GetAllLocationsInLibrary(); SelectList locs = new SelectList(locationsInLibrary, "IDLocationInLibrary", "Name"); Session["locationInLibrary"] = locs; return(RedirectToAction("Index")); } catch { return(View("CreateBook")); } }
public ViewResult Index() { //Simply access dynamic properties from controller to view //The scope of ViewBag is to only the view of current controller ViewBag.StrTitle = "Book Home"; // if we access ViewBag.StrData on view, it will simply print the array but we can not get anonymous types (individual array properties) this way. ViewBag.StrData = new { Id = 1, StrName = "Rashid" }; //In order to access properties of dynanic data object, we have to use ExandoObject. //This is how we can pass anonymous types to view from controller dynamic dDataExtender = new ExpandoObject(); dDataExtender.Id = 1; dDataExtender.StrName = "Rashid Ansari"; ViewBag.StrData2 = dDataExtender; //see how can we pass an object to View from controller ViewBag.oObject = new Models.BookModel() { Id = 500, StrTitle = "Book-500" }; //we can also use ViewData[""] to pass values from Controller to View; and also from view to Layout file. //Viewdata is type safe for complex objects and we can pass get types of object elements so it will //catch compilation errors, if any. ViewData["StrTitleFromViewData"] = "This is the Title from ViewData"; ViewData["oObjectFromViewData"] = new Models.BookModel() { Id = 600, intPages = 1000, StrTitle = "Book Title From ViewData Object(600)" }; var data = _bookRepository.GetAllBooks(); return(View(data)); //return View(); }
public void AddBook(Models.BookModel search) { var id = HttpContext.User.FindFirst("id"); if (id == null) { throw new Exceptions.AuthorizationException("Ошибка аутентификации, отсутствуют дополнительные параметры пользователя"); } using (BookDb.BookDbContext db = new BookDb.BookDbContext()) { using (var scope = db.Database.BeginTransaction()) { var lnk = new BookDb.LnkUserBook(); lnk.BookId = search.bookId.Value; lnk.UserId = int.Parse(id.Value); db.LnkUserBook.Add(lnk); db.SaveChanges(); scope.Commit(); } } }
public Models.BookModel ReturnBook(string ISBN) { Models.BookModel book = null; searchKeyString = searchKeys[0]; XmlNode returnnode = root.SelectSingleNode($"//Product/{searchKeyString}[text()='{ISBN}']/ancestor::Product"); if (returnnode != null) { var BkISBN = returnnode.SelectSingleNode($".//RecordReference/text()").Value; var Title = returnnode.SelectSingleNode($".//Title/TitleText/text()").Value; var Price = returnnode.SelectSingleNode($".//Price/PriceAmount/text()").Value; var Author = returnnode.SelectSingleNode($".//PersonNameInverted/text()").Value; var AuthorText = returnnode.SelectSingleNode($".//OtherText[TextTypeCode=13]/Text/text()").Value; var Desc = returnnode.SelectSingleNode($".//OtherText[TextTypeCode=18]/Text/text()").Value; var Reviews = returnnode.SelectSingleNode($".//OtherText[TextTypeCode=08]/Text/text()").Value; var PubDate = returnnode.SelectSingleNode($".//PublicationDate/text()").Value; var Publisher = returnnode.SelectSingleNode($".//Publisher/PublisherName/text()").Value; var PageNmbr = returnnode.SelectSingleNode($".//NumberOfPages/text()").Value; book = new Models.BookModel(BkISBN, Title, Price, Author, AuthorText, Desc, PubDate, Reviews, Publisher, PageNmbr); } return(book); }
public ActionResult Edit(Guid id) { Models.BookModel bookModel = bookRepository.GetBookByID(id); return(View("EditBook", bookModel)); }
public BookDetailsPanel(Models.BookModel selectedBookToDisplay) { InitializeComponent(); DataContext = new ViewModels.BookDetailsPanelViewModel(selectedBookToDisplay); }
public BookDetailsPanelViewModel(Models.BookModel selectedBookToDisplay) { selectedBook = selectedBookToDisplay; }