public async Task <LearningResource> Update(LearningResource learningResource)
        {
            _context.Entry(learningResource).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(learningResource);
        }
예제 #2
0
        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 <CinematicItem> Update(CinematicItem cinematicItem)
        {
            _context.Entry(cinematicItem).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(cinematicItem);
        }
예제 #4
0
        public async Task <ResourceList> Update(ResourceList resourceList)
        {
            _context.Entry(resourceList).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(resourceList);
        }
예제 #5
0
 public void Update(T entity)
 {
     _context.Entry(entity).State =
         EntityState.Modified;
     Save();
 }