public async Task <IActionResult> Edit(int id, [Bind("ID,Title,AuthorID,LanguageID")] Book book)
        {
            if (book.ID != id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(book);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookExists(book.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            ViewBag.Languages = new SelectList(_context.Languages.AsNoTracking(), "ID", nameof(Language.Name), book.LanguageID);
            ViewBag.Authors   = new SelectList(_context.Authors.AsNoTracking(), "ID", nameof(Author.Name), book.AuthorID);

            return(View(book));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name")] Author author)
        {
            if (author.ID != id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(author);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    //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(RedirectToAction(nameof(Index)));
            }
            return(View(author));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name")] Language language)
        {
            if (language.ID != id)
            {
                return(NotFound());
            }

            if (await TryUpdateModelAsync <Language>(language, nameof(language),
                                                     l => l.Name))
            {
                try
                {
                    _context.Update(language);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LanguageExists(language.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(language));
        }