// GET: Books/Edit/5 public ActionResult Edit(int id) { BooksModel bookmodel = new BooksModel(); DataTable dttblBook = new DataTable(); using (SqlConnection sqlcon = new SqlConnection(connectionString)) { sqlcon.Open(); string query = "SELECT * FROM ListBooks Where BooksId = @BooksId"; SqlDataAdapter sqlda = new SqlDataAdapter(query, sqlcon); sqlda.SelectCommand.Parameters.AddWithValue("@BooksId", id); sqlda.Fill(dttblBook); } if (dttblBook.Rows.Count == 1) { bookmodel.BooksId = Convert.ToInt32(dttblBook.Rows[0][0].ToString()); bookmodel.Title = (dttblBook.Rows[0][1].ToString()); bookmodel.Author = (dttblBook.Rows[0][2].ToString()); bookmodel.DatePublished = Convert.ToDateTime(dttblBook.Rows[0][3].ToString()); bookmodel.Pages = Convert.ToInt32(dttblBook.Rows[0][4].ToString()); bookmodel.Type = (dttblBook.Rows[0][5].ToString()); return(View(bookmodel)); } else { return(RedirectToAction("Index")); } }
public BooksViewModel() { NewBookCommand = new ActionCommand((o) => CreateBook()); CheckStatusCommand = new ActionCommand((o) => CheckStatus()); BooksModel = new BooksModel(); LoadBooks(); }
public ActionResult AddBook(FormCollection collection) { try { //9780596007126 - Head First Design Patterns string isbn = collection["isbn"]; HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn + "&key=AIzaSyARYJrBPVJ9B77JveSDkwPI5IvWUGVHe1M"); GoogleBooksApiReader bookInformation = new GoogleBooksApiReader((HttpWebResponse)request.GetResponse()); if (bookInformation.isValid()) { BooksModel addBook = new BooksModel(bookInformation); db.BooksModels.Add(addBook); db.SaveChanges(); ViewBag.bookIsbnException = null; return(RedirectToAction("Index")); } else { ViewBag.bookIsbnException = "Wrong ISBN code!"; throw new Exception("Wrong ISBN code"); } } catch (Exception e) { Console.WriteLine(e.Message); return(View()); } }
public ActionResult Create(BooksModel Z) { try { Book book = new Book() { Title = Z.Title, Author = Z.Author, Genre = Z.Genre, Rating = Z.Rating, Sinopsis = Z.Sinopis, Price = Z.Price, Stock = Z.Stock, Shelves = Z.Shelves }; context.Books.InsertOnSubmit(book); context.SubmitChanges(); return(RedirectToAction("Index")); } catch { return(View(Z)); } }
public BookFormViewModel() { BooksModel = new BooksModel(); SaveCommand = new ActionCommand((o) => Save()); CancelCommand = new ActionCommand((o) => Cancel()); BrowseImageCommand = new ActionCommand((o) => BrowseImage()); }
public AccountTakenBooksViewModel(int accountId) { AccountId = accountId; AccountsModel = new AccountsModel(); BooksModel = new BooksModel(); CloseCommand = new ActionCommand((o) => Close()); LoadBooks(); }
//[Authorize(Roles = "Admin")] public IActionResult Post(BooksModel book) { if (_bookservice.Create(book)) { return(Ok()); } return(BadRequest()); }
public ActionResult DeleteConfirmed(int id) { BooksModel booksmodel = db.Books.Find(id); db.Books.Remove(booksmodel); db.SaveChanges(); return(RedirectToAction("index", "home")); }
public ActionResult Add() { BooksModel book = new BooksModel(); book.Publishers = GetP(); book.Authors = GetA(); return(View(book)); }
public IActionResult GetBooks() { var tableModel = new DataTablesAjaxRequestModel(Request); var model = new BooksModel(); var data = model.GetBooks(tableModel); return(Json(data)); }
public async void UpdateOne(BooksModel book) { await _mongoCollection.FindOneAndUpdateAsync( Builders <BooksModel> .Filter.Eq(b => b.Number, book.Number), Builders <BooksModel> .Update.Set(b => b.Number, book.Number) .Set(b => b.Title, book.Title) .Set(b => b.Author, book.Author) ); }
public ActionResult Index() { //IBooksRepository repository; BooksModel booksModel = new BooksModel(); booksModel.Books = repository.GetBooks(); return(View(booksModel)); }
//[Authorize(Roles = "Admin")] public IActionResult Put(int id, BooksModel book) { id = book.BookID; if (_bookservice.Update(book)) { return(Ok()); } return(BadRequest()); }
public void AddNewBook() { BooksModel classObj = new BooksModel(); BooksModel obj = new BooksModel(); obj.Author = "Test Author"; obj.Title = "Test Title"; Assert.IsTrue(classObj.AddNewBook(obj)); }
public ActionResult Books(string userId) { var books = new BooksModel { books = new DataAccessor().GetBooksForUser(userId) }; return(View(books)); }
public ActionResult Edit(BooksModel booksmodel) { if (ModelState.IsValid) { db.Entry(booksmodel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("index", "home")); } return(View(booksmodel)); }
// // GET: /Books/Delete/5 public ActionResult Delete(int id = 0) { BooksModel booksmodel = db.Books.Find(id); if (booksmodel == null) { return(HttpNotFound()); } return(View(booksmodel)); }
// GET: BookManagement public ActionResult Index(int page = 1, string message = null) { var model = new BooksModel { Message = message }; var pagedBooks = Service.GetBooks(page); var books = Mapper.Map <IEnumerable <Book>, IEnumerable <BookModel> >(pagedBooks.ToArray()); model.Books = new StaticPagedList <BookModel>(books, pagedBooks.GetMetaData()); return(View(model)); }
public ActionResult Search(string inputText) { var bookSummaries = new BookOrganiser().GetSummaryOfBooks(new DataAccessor().SearchBooks(inputText)); var bookModel = new BooksModel { BookSummaries = bookSummaries }; return(View("Catalogue", bookModel)); }
public BookListViewModel(BooksModel booksModel) { BooksModel = booksModel; collectionViewSource = new CollectionViewSource { Source = BooksModel.Books }; collectionViewSource.View.Filter = (o) => FilterBook((Book)o); SelectedFilter = 0; Books = collectionViewSource.View; }
public void GetAllBooks() { // Arrange BooksModel model = new BooksModel(); Common.SearchCriteria obj = new Common.SearchCriteria(); obj.StartIndex = 0; obj.EndIndex = 10; obj.Text = string.Empty; Assert.IsNotNull(model.GetAllBooks(obj)); Assert.AreEqual(10, model.GetAllBooks(obj).Count); }
public ActionResult Catalogue() { var books = new DataAccessor().GetListOfAllBooks(); var bookSummaries = new BookOrganiser().GetSummaryOfBooks(books); var booksModel = new BooksModel { BookSummaries = bookSummaries }; return(View(booksModel)); }
public ActionResult Create(BooksModel booksmodel) { if (ModelState.IsValid) { db.Books.Add(booksmodel); db.SaveChanges(); return(RedirectToAction("index", "home")); //return RedirectToAction("Index"); } return(View(booksmodel)); }
public BookDialogViewModel(Book book, BooksModel booksModel) { Book = book; BooksModel = booksModel; if (Book != null) { Title = book.Title; Author = book.Author; Year = book.Year; Category = book.Category; } //dialogResult = false; }
public async Task <IActionResult> Edit(BooksModel booksModel) { if (ModelState.IsValid) { await _bookservice.UpdateBook(booksModel); return(RedirectToAction("Index")); } else { return(View()); } }
public bool Create(BooksModel book) { try { _context.Books.Add(book); _context.SaveChanges(); return(true); } catch { return(false); } }
public ActionResult SaveUpdate(BooksModel booksModel) { if (booksModel.ID == 0) { HttpResponseMessage response = BookCollectionClass.Client.PostAsJsonAsync("Books", booksModel).Result; TempData["SuccessMessage"] = "Saved Successfully"; } else { HttpResponseMessage response = BookCollectionClass.Client.PutAsJsonAsync("Books/" + booksModel.ID, booksModel).Result; TempData["SuccessMessage"] = "Updated Successfully"; } return(RedirectToAction("Index")); }
/// <summary> /// Loads the library if it isn't already. /// </summary> /// <returns></returns> private async System.Threading.Tasks.Task RetrieveLibrary() { if (LibrarySource == null) { LibrarySource = new BooksModel(); if (!LibrarySource.IsDataLoaded) { await LibrarySource.LoadData(); } DataContext = LibrarySource; LibraryListView.ItemsSource = LibrarySource.SortedBooks; RecentReadsListView.ItemsSource = LibrarySource.RecentBooks; } }
public ActionResult Create(BooksModel bookmodel) { using (SqlConnection sqlcon = new SqlConnection(connectionString)) { sqlcon.Open(); string query = "INSERT INTO ListBooks VALUES(@Title,@Author,@DatePublished,@Pages,@Type)"; SqlCommand sqlcmd = new SqlCommand(query, sqlcon); sqlcmd.Parameters.AddWithValue("@Title", bookmodel.Title); sqlcmd.Parameters.AddWithValue("@Author", bookmodel.Author); sqlcmd.Parameters.AddWithValue("@DatePublished", bookmodel.DatePublished); sqlcmd.Parameters.AddWithValue("@Pages", bookmodel.Pages); sqlcmd.Parameters.AddWithValue("@Type", bookmodel.Type); sqlcmd.ExecuteNonQuery(); } return(RedirectToAction("Index")); }
public bool Update(BooksModel book) { try { var item = _context.Books.FirstOrDefault(x => x.BookID == book.BookID); item.BookID = book.BookID; item.BookName = book.BookName; item.Image = book.Image; item.CategoryID = book.CategoryID; _context.SaveChanges(); return(true); } catch { return(false); } }