/// <summary> /// SearchISBN - calls ISBN.SearchTitleByIsbn to get the Title of the given ISBN code. /// </summary> /// <param name="isbn"></param> /// <returns>title-typeof(string)</returns> public ActionResult SearchISBN(string isbn) { string title = ""; if (isbn is null) { return(Json(title, JsonRequestBehavior.AllowGet)); } title = ISBN.SearchTitleByIsbn(isbn); return(Json(title, JsonRequestBehavior.AllowGet)); }
public ActionResult Create([Bind(Include = "Id,ISBN,Title,Mark")] Book book) { if (ModelState.IsValid) { book.ISBN = book.ISBN.Trim(); var userIdQuery = db.Users.Where(u => u.Email == User.Identity.Name).Select(u => u.Id); var userId = userIdQuery.FirstOrDefault(); //Check if ISBN is already exist in book list if (db.Books.Where(b => b.ISBN == book.ISBN && b.UserId == userId).Count() > 0) { // TempData["error"] = "Book with ISBN + " + book.ISBN + " already exists in your list."; ModelState.AddModelError("", "Book with ISBN : " + book.ISBN + " already exists in your list."); return(View(book)); // return RedirectToAction("form_Post", "Form"); } //Search for the title by ISBN through ISBNdb.com //This is just an alternative, for Search Button in CreateView string title = ISBN.SearchTitleByIsbn(book.ISBN); if (title != null) { book.Title = title; } book.UserId = userId; book.AddedDate = DateTime.Now; db.Books.Add(book); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(book)); }