public void ReturnBook(int bookID) { var book = _context.BookOrders.Where(b => b.BookId == bookID).SingleOrDefault(); book.IsReturned = true; _context.Update(book); _context.SaveChanges(); }
private void ChangeCountBooksOnStore(List <BookOrder> booksOrder) { booksOrder.ForEach((BookOrder bo) => { var book = _context.Books.Where(b => b.Id == bo.BookId).SingleOrDefault(); if (book.Count < bo.CountOfBook) { throw new Exception("Кол-во книг на складе меньше кол-ва книг для пользователя"); } book.Count -= bo.CountOfBook; _context.Update(book); }); _context.SaveChanges(); }
public async Task <IActionResult> Edit(string id, [Bind("Id,Name,AuthorId,CollectionId,Year,GenreId")] 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))); } ViewData["AuthorId"] = new SelectList(_context.Author, "Id", "Id", book.AuthorId); ViewData["CollectionId"] = new SelectList(_context.Collection, "Id", "Id", book.CollectionId); return(View(book)); }
public async Task <IActionResult> Edit(string id, [Bind("Id,Content,BookId")] Review review) { if (id != review.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(review); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReviewExists(review.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["BookId"] = new SelectList(_context.Book, "Id", "Id", review.BookId); return(View(review)); }
public async Task <IActionResult> PutBook([FromRoute] int id, [FromBody] Book book) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != book.BookId) { return(BadRequest()); } _context.Update(book); // _context.Entry(book).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Edit(int id, [Bind("ID,FirstName,LastName,DateOfBirth,Mobile,Address,City,Province,Country,PostalCode")] UserProfileModel userProfileModel) { if (id != userProfileModel.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(userProfileModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserProfileModelExists(userProfileModel.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(userProfileModel)); }
public async Task <IActionResult> Edit(int id, Two twoR) { if (id != twoR.Book.ID) { return(NotFound()); } if (ModelState.IsValid) { try { twoR.Book.Author = _context.Author.Where(r => r.ID == twoR.Book.AuthorRefId).SingleOrDefault(); _context.Update(twoR.Book); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookExists(twoR.Book.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } Two two = new Two(); two.Authors = _context.Author.ToList(); two.Book = twoR.Book; return(View(two)); }
public async Task <IActionResult> Edit(string id, [Bind("Id,Title")] Collection collection) { if (id != collection.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(collection); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CollectionExists(collection.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(collection)); }
public async Task <IActionResult> Edit(int id, [Bind("id,userId")] ReadingCard readingCard) { if (id != readingCard.id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(readingCard); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReadingCardExists(readingCard.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["userId"] = new SelectList(_context.User, "id", "id", readingCard.userId); return(View(readingCard)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Title,Description,Author,ISBN,College,Rate,ImagePath")] BookADS bookADS) { if (id != bookADS.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(bookADS); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookADSExists(bookADS.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(bookADS)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Email,Score,Comments")] Review review) { if (id != review.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(review); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReviewExists(review.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(review)); }
public async Task <IActionResult> Edit(string id, [Bind("Id,Name,Surname")] Author author) { if (id != author.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(author); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AuthorExists(author.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(author)); }
public async Task <IActionResult> Edit(int id, [Bind("BookId,UserId,Rating")] UserBook userBook) { if (id != userBook.BookId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(userBook); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserBookExists(userBook.BookId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["BookId"] = new SelectList(_context.Books, "Id", "Author", userBook.BookId); return(View(userBook)); }
public async Task <IActionResult> Edit(int id, [Bind("id,name")] Genre genre) { if (id != genre.id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(genre); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GenreExists(genre.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(genre)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Author,ISBN,ReleaseYear")] 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)); }
public async Task <IActionResult> Edit(int id, [Bind("id,name,description,imageUrl,genre,authorId,posterId")] 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))); } ViewData["authorId"] = new SelectList(_context.Author, "id", "id", book.authorId); ViewData["posterId"] = new SelectList(_context.Poster, "id", "id", book.posterId); return(View(book)); }
public async Task <IActionResult> AddOrEdit(int id, [Bind("Id,NameBook,GenreBook,AuthorBook,Pages,Data")] MyBooksModel booksModel) { if (ModelState.IsValid) { if (id == 0) { booksModel.Date = DateTime.Now; db.Add(booksModel); await db.SaveChangesAsync(); } // Обнова else { try { booksModel.Date = DateTime.Now; db.Update(booksModel); await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BooksModelExists(booksModel.Id)) { return(NotFound()); } else { throw; } } } return(Json(new { isValid = true, html = RenderRazorViewToString(this, "Index", db.Books.ToList()) })); } return(Json(new { isValid = false, html = RenderRazorViewToString(this, "AddOrEdit", booksModel) })); }
public async Task <IActionResult> Edit(string id, [Bind("Id,Title,AuthorId")] Comics comics) { if (id != comics.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(comics); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ComicsExists(comics.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["AuthorId"] = new SelectList(_context.Author, "Id", "Id", comics.AuthorId); return(View(comics)); }
public async Task <IActionResult> Edit(int id, [Bind("id,name,email,password,readingCardId")] 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)); }
public async Task <IActionResult> Edit(string id, [Bind("Id,GenreId,BookId")] BooksGenres booksGenres) { if (id != booksGenres.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(booksGenres); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BooksGenresExists(booksGenres.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["BookId"] = new SelectList(_context.Book, "Id", "Id", booksGenres.BookId); ViewData["GenreId"] = new SelectList(_context.Genre, "Id", "Id", booksGenres.GenreId); return(View(booksGenres)); }
public async Task <IActionResult> Edit(int id, [Bind("BookId,Isbn,Title,Publisher")] Book book) { if (id != book.BookId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(book); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookExists(book.BookId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(book)); }
public IActionResult UpdateStock(string isbn, [FromBody] Book bookIn) { Book book = _context.Book.FirstOrDefault(b => b.ISBN == isbn); int oldStock = book.Stock; int newStock = oldStock - 1; book.Stock = newStock; _context.Update(book); return(Ok(book)); }
public async Task <IActionResult> Edit(int id, Book book) { if (ModelState.IsValid) { _context.Update(book); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { return(View(book)); } }
public async Task <IActionResult> PutBook(Book book) { if (book == null) { return(BadRequest()); } if (!_context.Books.Any(x => x.Id == book.Id)) { return(NotFound()); } _context.Update(book); await _context.SaveChangesAsync(); return(Ok(book)); }
public async Task UpdateBookAsync() { Book?book = await _booksContext.Books.FindAsync(1); if (book != null) { // detach the existing object from the context which allows to attach it with the Update method _booksContext.Entry(book).State = EntityState.Detached; Book bookUpdate = book with { Title = "Professional C# and .NET - 2021 Edition" }; _booksContext.Update(bookUpdate); int records = await _booksContext.SaveChangesAsync(); Console.WriteLine($"{records} record updated"); } Console.WriteLine(); }
public async Task <IActionResult> UpdateAsync([FromBody] Libros libro) { if (ModelState.IsValid) { try { var _libro = await _context.Libros.SingleOrDefaultAsync(i => i.Isbn == libro.Isbn); if (_libro == null) { return(NotFound()); } _libro.Titulo = libro.Titulo; _libro.Sinopsis = libro.Sinopsis; _libro.NPaginas = libro.NPaginas; _libro.EditorialesId = libro.EditorialesId; _libro.Editoriales = await _context.Editoriales.SingleOrDefaultAsync(x => x.Id == libro.EditorialesId); _context.Update(_libro); await _context.SaveChangesAsync(); return(Ok(_libro)); } catch (DbUpdateConcurrencyException) { if (!LibroExists(libro.Isbn)) { return(NotFound()); } else { throw; } } } else { return(BadRequest()); } }
public async Task <IActionResult> UpdateAsync([FromBody] Autores autor) { if (ModelState.IsValid) { try { var _autor = await _context.Autores.SingleOrDefaultAsync(i => i.Id == autor.Id); if (_autor == null) { return(NotFound()); } _autor.Nombre = autor.Nombre; _autor.Apellidos = autor.Apellidos; _context.Update(_autor); await _context.SaveChangesAsync(); return(Ok(_autor)); } catch (DbUpdateConcurrencyException) { if (!AutoresExists(autor.Id)) { return(NotFound()); } else { throw; } } } else { return(BadRequest()); } }
public string Update(T item) { booksContext.Update(item); return(item.id + " updated..."); }
public void IncCountBooks(Book book) { book.Count++; _context.Update(book); _context.SaveChanges(); }
public async Task EditElem(Order elem) { _context.Update(elem); await _context.SaveChangesAsync(); }