public ActionResult Return(string id) { if (string.IsNullOrEmpty(id)) { return(RedirectToAction("Index")); } var model = new BookViewModel(); var bookBuilder = new BookModelBuilder(); var modelList = bookBuilder.CreateModelList(b => b.ISBN.StartsWith(id), 0, 1); if (modelList.Any()) { model = modelList.FirstOrDefault(); var userName = User.Identity.Name; var userBuilder = new LibraryUserModelBuilder(); var userModel = userBuilder.BuildModelFrom(userName); ViewBag.IsBookRentByMe = userModel.RentBooks != null && userModel.RentBooks.Where(r => r.ISBN.CompareTo(model.ISBN) == 0).Any(); } else { return(RedirectToAction("Index")); } return(View(model)); }
// GET: Book public ActionResult Index() { var bookBuilder = new BookModelBuilder(); var model = bookBuilder.CreateModelList(b => !string.IsNullOrEmpty(b.BookName), 0, 20); return(View(model)); }
public bool CheckISBNExisted(string ISBN) { bool result = false; if (!string.IsNullOrEmpty(ISBN)) { var bookBuilder = new BookModelBuilder(); var books = bookBuilder.CreateModelList(b => b.ISBN.CompareTo(ISBN) == 0, 0, 1); result = books.Any(); } return(result); }
public ActionResult Rent(string id) { if (string.IsNullOrEmpty(id)) { return(RedirectToAction("Index")); } var model = new BookViewModel(); var bookBuilder = new BookModelBuilder(); var modelList = bookBuilder.CreateModelList(b => b.ISBN.StartsWith(id), 0, 1); if (modelList.Any()) { model = modelList.FirstOrDefault(); } else { return(RedirectToAction("Index")); } return(View(model)); }