Example #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));
        }
Example #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));
        }
        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));
        }
Example #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));
        }
Example #7
0
        public async Task <IActionResult> Save([FromBody] Book book)
        {
            _context.Update(book);

            await _context.SaveChangesAsync();

            return(Json(""));
        }
Example #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"));
        }
Example #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();
        }