Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("AuthorId,MyProperty")] Author author)
        {
            if (id != author.AuthorId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(author);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AuthorExists(author.AuthorId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                ViewBag.Title   = "Author updated successfully";
                ViewBag.Message = "Author updated successfully!";
                return(View("Success"));
            }
            return(View(author));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Author,ISBN")] Book book)
        {
            if (id != book.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)));
            }
            return(View(book));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, [Bind("AuthorId,Name")] Author author)
        {
            if (id != author.AuthorId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(author);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AuthorExists(author.AuthorId))
                    {
                        // todo: talvez alguem apagou isto
                        //informar o user se quer criar um novo com os mesmos dados
                        return(NotFound());
                    }
                    else
                    {
                        // todo: mostrar o erro e perguntar se quer tentar outra vez
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(author));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,タイトル,著者,出版社,発行日,分野,リンク")] Books books)
        {
            if (id != books.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(books);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BooksExists(books.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(books));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, [Bind("AuthorId,Name")] Author author)
        {
            if (id != author.AuthorId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(author);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    // Maybe consider doing something different
                    if (!AuthorExists(author.AuthorId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                ViewBag.Title   = "Author updated successfully";
                ViewBag.Message = "The author was updated successfully.";

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

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Save([FromBody] Book book)
        {
            _context.Update(book);

            await _context.SaveChangesAsync();

            return(Json(""));
        }
Exemplo n.º 8
0
        public IActionResult UpdateBook(Book newBook)
        {
            Book oldBook = _context.Books.Find(newBook.Id);

            if (ModelState.IsValid)
            {
                oldBook.Title  = newBook.Title;
                oldBook.Author = newBook.Author;
                _context.Entry(oldBook).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                _context.Update(oldBook);
                _context.SaveChanges();
            }
            return(RedirectToAction("BooksList"));
        }
Exemplo n.º 9
0
        public async Task Put([FromBody] Book book)
        {
            _dataContext.Update(book);

            await _dataContext.SaveChangesAsync();
        }
        public async Task Save([FromBody] Book book)
        {
            _context.Update(book);

            await _context.SaveChangesAsync();
        }