public async Task <IActionResult> Create([Bind("ID, StudentID, BookID, TakingDate")] BookTakenCreateVM bookTakenCreateVM) { if (ModelState.IsValid) { BookTaken issue = new BookTaken() { TakenBy = bookTakenCreateVM.StudentID, TakenBook = bookTakenCreateVM.BookID, TakingDate = bookTakenCreateVM.TakingDate }; _context.BookTaken.Add(issue); //await _context.SaveChangesAsync(); int bookID = issue.TakenBook; var bookToUpdate = await _context.Book .FirstOrDefaultAsync(s => s.ID == bookID); bookToUpdate.Quantity -= 1; if (await TryUpdateModelAsync <Book>( bookToUpdate, "Book", i => i.ID, i => i.Title, i => i.Author, i => i.Quantity)) { } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(bookTakenCreateVM)); }
// GET: BookTakens/Create public IActionResult Create() { //return View(); var AllStudentsList = new BookTakenCreateVM(this._context); return(View(AllStudentsList)); }