Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("AuthorId,FirstName,LastName")] Author author)
        {
            if (id != author.AuthorId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    using (var context = new EFCoreWebDemoContext())
                    {
                        context.Update(author);
                        await context.SaveChangesAsync();
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AuthorExists(author.AuthorId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            //return View(author);
            return(RedirectToAction("Index"));
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, [Bind("BookId,Title,AuthorId")] Book book)
        {
            if (id != book.BookId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    using (var _context = new EFCoreWebDemoContext())
                    {
                        _context.Update(book);
                        await _context.SaveChangesAsync();
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookExists(book.BookId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            using (var _context = new EFCoreWebDemoContext())
            {
                ViewData["AuthorId"] = new SelectList(_context.Authors, "AuthorId", "AuthorId", book.AuthorId);
            }
            return(View(book));
        }