public async Task <IActionResult> Create([Bind("RentedBookID,StudentID,BookID,RentDate,ReturnDate")] RentedBook rentedBook) { Book book = _context.Books.Find(rentedBook.BookID); var checkBook = _context.RentedBooks .Include(r => r.Book) .Include(r => r.Student).ToList(); // if there are more than 1, book will be issued if (book.AvailableQuantity >= 1) { book.AvailableQuantity -= 1; _context.Entry(book).State = EntityState.Modified; if (ModelState.IsValid) { _context.Add(rentedBook); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } // if none, give a message telling user that the book is current unavailable else { ModelState.AddModelError(string.Empty, "The book is unavailable! It is rented by other students."); } ViewData["BookID"] = new SelectList(_context.Books, "BookID", "BookID", rentedBook.BookID); ViewData["StudentID"] = new SelectList(_context.Students, "StudentID", "StudentID", rentedBook.StudentID); return(View(rentedBook)); }
public async Task <LearningResource> Add(LearningResource learningResource) { _context.LearningResources.Add(learningResource); await _context.SaveChangesAsync(); return(learningResource); }
public async Task <CinematicItem> Add(CinematicItem cinematicItem) { _context.CinematicItems.Add(cinematicItem); await _context.SaveChangesAsync(); return(cinematicItem); }
public async Task <ResourceList> Add(ResourceList resourceList) { _context.ResourceLists.Add(resourceList); await _context.SaveChangesAsync(); return(resourceList); }
public async Task <IActionResult> Create([Bind("Id,Name")] ResourceList resourceList) { if (ModelState.IsValid) { _context.Add(resourceList); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(resourceList)); }
public async Task <IActionResult> Create([Bind("Id,TagValue")] TopicTag topicTag) { if (ModelState.IsValid) { _context.Add(topicTag); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(topicTag)); }
public async Task <IActionResult> Create([Bind("Id,Name,Description,Phase,ReleaseDate")] CinematicItem cinematicItem) { if (ModelState.IsValid) { _context.Add(cinematicItem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(cinematicItem)); }
public async Task <IActionResult> Create([Bind("Id,FeedUrl,LearningResourceId")] ContentFeed contentFeed) { if (ModelState.IsValid) { _context.Add(contentFeed); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["LearningResourceId"] = new SelectList(_context.LearningResources, "Id", "Id", contentFeed.LearningResourceId); return(View(contentFeed)); }
public async Task <IActionResult> Create([Bind("RentedBookID,StudentID,BookID,RentDate,ReturnDate")] RentedBook rentedBook) { if (ModelState.IsValid) { _context.Add(rentedBook); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BookID"] = new SelectList(_context.Books, "BookID", "BookID", rentedBook.BookID); ViewData["StudentID"] = new SelectList(_context.Students, "StudentID", "StudentID", rentedBook.StudentID); return(View(rentedBook)); }
public async Task <IActionResult> Create([Bind("BookName,Author,Edition,ISBN,Subject,PublicDate,Format,NumofPages,AvailableQuantity")] Book book) { try { if (ModelState.IsValid) { _context.Add(book); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException /* ex */) { ModelState.AddModelError("", "Unable to save changes. " + "Please check if there are any errors with the database"); } return(View(book)); }
public async Task <IActionResult> Create([Bind("StudentFirstName,StudentLastName,StudentEmail,StudentPhoneNumber")] Student student) { try { if (ModelState.IsValid) { _context.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } return(View(student)); }