public async Task <IActionResult> Save([FromBody] Book book) { _context.Update(book); await _context.SaveChangesAsync(); return(Json("")); }
public async Task <ActionResult <Books> > Post([FromBody] Books books) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Books.Add(books); var val = await _context.SaveChangesAsync(); return(Ok(books)); }
public async Task <IActionResult> Create([Bind("Id,Title,Author,ISBN,LoanedTo")] Book book) { if (ModelState.IsValid) { _context.Add(book); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(book)); }
public async Task <IActionResult> Create([Bind("Id,タイトル,著者,出版社,発行日,分野,リンク")] Books books) { if (ModelState.IsValid) { _context.Add(books); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(books)); }
public async Task <IActionResult> Create([Bind("Id,Name")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(user)); }
public async Task <IActionResult> Create([Bind("BookId,Title,AuthorId")] Book book) { if (ModelState.IsValid) { _context.Add(book); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["AuthorId"] = new SelectList(_context.Author, "AuthorId", "Name", book.AuthorId); return(View(book)); }
[ValidateAntiForgeryToken] //validacao de seguranca public async Task <IActionResult> Create([Bind("AuthorId,Name")] Author author) //serve para evitar alguns ataques, só recebo os campos que estão no bind { if (ModelState.IsValid) { //todo: validacoes adicionais antes de inserir o autor _context.Add(author); await _context.SaveChangesAsync(); //todo: informar o user, autor criado com sucesso return(RedirectToAction(nameof(Index))); } return(View(author)); }
public async Task <IActionResult> Create([Bind("AuthorId,MyProperty")] Author author) { if (ModelState.IsValid) { _context.Add(author); await _context.SaveChangesAsync(); ViewBag.Title = "Author added successfully"; ViewBag.Message = "New author created successfully!"; return(View("Success")); } return(View(author)); }
/// <summary> /// Creates a book resource /// </summary> /// <param name="book">The book resource to be created</param> /// <returns>A Task to be awaited</returns> public async Task CreateAsync(Book book) { _logger.LogDebug("Attempting to create a @{book} resource", book); if (book == null) { _logger.LogError("Failed to create @{book} resource because it was null", book); throw new ArgumentNullException(nameof(book)); } await _context.Books.AddAsync(book); await _context.SaveChangesAsync(); _logger.LogDebug("Created the @{book} resource", book); }
public async Task <IActionResult> PutReview(long id, Review review) { if (id != review.Id) { return(BadRequest()); } if (!ReviewExists(id)) { return(NotFound()); } _context.Entry(review).State = EntityState.Modified; await _context.SaveChangesAsync(); return(Ok(review)); }
public async Task <IActionResult> PutBook(long id, Book book) { if (id != book.Id) { return(BadRequest()); } if (!BookExists(id)) { return(NotFound()); } _context.Entry(book).State = EntityState.Modified; await _context.SaveChangesAsync(); return(Ok(book)); }
public async Task <IActionResult> Delete(int id) { var bookFromDb = await _db.Books.FirstOrDefaultAsync(u => u.Id == id); if (bookFromDb == null) { return(Json(new { success = false, message = "Error while Deleting" })); } _db.Books.Remove(bookFromDb); await _db.SaveChangesAsync(); return(Json(new { success = true, message = "Delete successful" })); }
public async Task <ActionResult> AddBookAsync() { var book = new Book { Title = "Dzienniki Gwiazdowe", Description = "Sci-Fi", Publisher = "Nova" }; book.Authors.Add(new Author { FirstName = "Stanislaw", LastName = "Lem" }); db.Books.Add(book); await db.SaveChangesAsync(); return(Ok("book sucesfully saved")); }
public async Task Post([FromBody] Book book) { _dataContext.Add(book); await _dataContext.SaveChangesAsync(); }
public async Task <bool> saveChangesAsyn() { return(await _context.SaveChangesAsync() > 0); }
public async Task SaveChangesAsync() { await _context.SaveChangesAsync(); }
public async Task Save([FromBody] Book book) { _context.Update(book); await _context.SaveChangesAsync(); }