public IActionResult Create(LibraryAssetCV libraryAssetCV) { if (ModelState.IsValid) { var duplicate = _context.Books.Any(a => a.Author == libraryAssetCV.Author && a.ISBN == libraryAssetCV.ISBN); if (duplicate) { Book book = new Book() { NumberOfCopies = libraryAssetCV.NumberOfCopies, DewyIndex = libraryAssetCV.DewyIndex, Author = libraryAssetCV.Author, Cost = libraryAssetCV.Cost, ImageUrl = libraryAssetCV.ImageUrl, ISBN = libraryAssetCV.ISBN, Location = libraryAssetCV.Location, Title = libraryAssetCV.Title, Year = libraryAssetCV.Year, }; _context.Add(book); _context.SaveChanges(); return(RedirectToAction("Index")); } else { TempData["ErrorMessage"] = "Item is already exist"; } } return(View(libraryAssetCV)); }
// GET: Book/Edit/5 public IActionResult Edit(int id) { //if (id == null) //{ // return NotFound(); //} var book = _context.Books.Include(a => a.Location).Include(a => a.status).Where(c => c.Id == id).FirstOrDefault(); if (book == null) { return(NotFound()); } else { LibraryAssetCV libraryAssetCV = new LibraryAssetCV() { NumberOfCopies = book.NumberOfCopies, DewyIndex = book.DewyIndex, Author = book.Author, Cost = book.Cost, ImageUrl = book.ImageUrl, ISBN = book.ISBN, Location = book.Location, Title = book.Title, Year = book.Year, }; ViewBag.LocationList = new SelectList(_context.LibraryBranches.ToList(), "Id", "Name", book.Location.Id); ViewBag.StatusList = new SelectList(_context.Statuses.ToList(), "Id", "Name", book.status.Id); return(View(libraryAssetCV)); } }
public IActionResult Create() { LibraryAssetCV libraryAssetCV = new LibraryAssetCV(); libraryAssetCV.StatusesList = _context.Statuses.Select(a => new SelectListItem() { Value = a.Id.ToString(), Text = a.Name }); libraryAssetCV.LibraryBranchesList = _context.LibraryBranches.Select(a => new SelectListItem() { Value = a.Id.ToString(), Text = a.Name }); return(View(libraryAssetCV)); }