public ActionResult Edit(int bookID, BookEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.BookID != bookID) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateBookService(); if (service.UpdateBook(model)) { TempData["SaveResult"] = "Your book was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your book could not be updated."); return(View(model)); }
public bool UpdateBook(BookEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Books .Single(e => e.BookId == model.BookId); entity.BookId = model.BookId; entity.Title = model.Title; entity.PublicationDate = model.PublicationDate; entity.ISBN = model.ISBN; entity.GenreOfBook = model.GenreOfBook; entity.FormatOfBook = model.FormatOfBook; entity.LoanedTo = model.LoanedTo; entity.Narrator = model.Narrator; entity.Translator = model.Translator; entity.Illustrator = model.Illustrator; entity.IsFirstEdition = model.IsFirstEdition; entity.IHaveRead = model.IHaveRead; entity.IOwn = model.IOwn; return(ctx.SaveChanges() == 1); } }
// Edit existing public BookBase EditExisting(BookEdit editedItem) { // Update the object var updatedItem = REdit(editedItem); // Return the object return(Mapper.Map <BookBase>(updatedItem)); }
public async Task Create([FromBody] BookEdit bookEdit) { if (bookEdit == null) { throw new Exception("Not found"); } await bookService.SaveAsync(bookEdit); }
public async Task SaveAsync(BookEdit bookEdit) { Book book = bookEdit.Id == null ? new Book() : await bookRepository.GetEntityAsync(bookEdit.Id.Value, true); mapper.Map(bookEdit, book); if (bookEdit.Id == null) { await bookRepository.AddAsync(book); } await bookRepository.SaveChangesAsync(); }
public ActionResult Edit(int id) { var service = CreateBookService(); var detail = service.GetBookById(id); var model = new BookEdit { BookId = detail.BookId, BookName = detail.BookName, Author = detail.Author }; return(View(model)); }
public ActionResult Edit(int bookID) { var service = CreateBookService(); var detail = service.GetBookByID(bookID); var model = new BookEdit { BookID = detail.BookID, Title = detail.Title, Author = detail.Author }; return(View(model)); }
public bool UpdateBook(BookEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Books .Single(e => e.BookId == model.BookId && e.OwnerId == _userId); entity.BookName = model.BookName; entity.Author = model.Author; return(ctx.SaveChanges() == 1); } }
public IHttpActionResult Put(BookEdit book) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateBookService(); if (!service.UpdateBook(book)) { return(InternalServerError()); } return(Ok()); }
public ActionResult Edit(int id) { var service = CreateBookService(); var detail = service.GetBookByID(id); var model = new BookEdit { BookID = detail.BookID, Title = detail.Title, Description = detail.Description, BookAuthor = detail.BookAuthor }; return(View(model)); }
protected void Edit_Click(object sender, EventArgs e) { GridViewRow row = ((Button)sender).Parent.Parent as GridViewRow; var bookId = int.Parse(BooksGrid.DataKeys[row.RowIndex].Value.ToString()); LibrarySystemDbContext data = new LibrarySystemDbContext(); var book = data.Books.FirstOrDefault(x => x.Id == bookId); BookEdit.DataSource = new List <Book> { book }; BookEdit.DataBind(); (BookEdit.FindControl("BookCategory") as DropDownList).SelectedValue = book.CategoryId.ToString(); }
public bool UpdateBook(BookEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Books .Single(e => e.BookID == model.BookID && e.UserID == _userID); entity.BookID = model.BookID; entity.Title = model.Title; entity.Author = model.Author; return(ctx.SaveChanges() == 1); } }
public async Task <IActionResult> Edit(BookEdit bookedit) { Book book = await this._context.Books.FindAsync(bookedit.Id); book.Name = bookedit.Name; book.Janre = bookedit.Janre; book.Author = bookedit.Author; book.Price = bookedit.Price; await this._context.SaveChangesAsync(); return(RedirectToAction("GetListOfBooks", "Book")); }
public async Task <IActionResult> Edit(int id) { Book book = await this._context.Books.FindAsync(id); BookEdit edit = new BookEdit() { Id = id, Name = book.Name, Author = book.Author, Janre = book.Janre, Price = book.Price, Year = book.Year }; return(View(edit)); }
//Update Book by id public async Task <bool> UpdateBook([FromUri] int id, [FromBody] BookEdit model) { Book Book = _context .Books .Single(a => a.BookId == id); Book.BookName = model.BookName; Book.Author = model.Author; Book.Rating = model.Rating; Book.NumberOfTimesRead = model.NumberOfTimesRead; Book.LastTimeRead = model.LastTimeRead; Book.PersonalSummary = model.PersonalSummary; return(await _context.SaveChangesAsync() == 1); }
public bool EditBook(BookEdit modelEdit) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Books .Single(e => e.Id == modelEdit.Id); entity.Name = modelEdit.Name; entity.Author = modelEdit.Author; entity.Genre = modelEdit.Genre; entity.PublishedDate = modelEdit.PublishedDate; entity.ModifiedUtc = DateTimeOffset.Now; return(ctx.SaveChanges() == 1); } }
public bool UpdateBook(BookEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Books .Single(e => e.BookId == model.BookId && e.OwnerId == _userId); entity.Title = model.Title; entity.AuthorName = model.AuthorName; entity.Description = model.Description; entity.BookGenre = model.BookGenre; entity.AvgBookRating = model.AvgBookRating; return(ctx.SaveChanges() == 1); } }
public bool UpdateBook(BookEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Books .Single(e => e.BookID == model.BookID); /*&& e.UserId == _userID);*/ entity.Title = model.Title; entity.Description = model.Description; entity.BookAuthor = model.BookAuthor; entity.ModifiedUtc = DateTimeOffset.UtcNow; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id) { var service = CreateBookService(); var detail = service.GetBookById(id); var model = new BookEdit { BookId = detail.BookId, Title = detail.Title, AuthorName = detail.AuthorName, Description = detail.Description, BookGenre = detail.BookGenre, AvgBookRating = detail.AvgBookRating }; return(View(model)); }
public bool UpdateBook(BookEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Books .Single(e => e.BookId == model.BookId && e.CreatorId == _creatorId); entity.BookName = model.BookName; entity.Genre = model.Genre; entity.Rating = model.Rating; entity.Price = model.Price; entity.PageCount = model.PageCount; entity.Description = model.Description; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id) { var service = CreateBookService(); var detail = service.GetBookById(id); var model = new BookEdit { BookId = detail.BookId, BookName = detail.BookName, Genre = detail.Genre, Rating = detail.Rating, Price = detail.Price, PageCount = detail.PageCount, Description = detail.Description }; return(View(model)); }
// GET: Edit public ActionResult Edit(int id) { BookDetail detail = GetBookService(id); var model = new BookEdit { BookId = detail.BookId, Title = detail.Title, SeriesTitle = detail.SeriesTitle, Isbn = detail.Isbn, Rating = detail.Rating, Genre = detail.Genre, Language = detail.Language, Publisher = detail.Publisher, IsEbook = detail.IsEbook }; return(View(model)); }
public ActionResult Edit(int ID) { var service = CreateBookService(); var detail = service.GetBookByID(ID); var model = new BookEdit { BookID = detail.BookID, Title = detail.Title, Author = detail.Author, Description = detail.Description, YearPublished = detail.YearPublished, DateRead = detail.DateRead, IsRecommended = detail.IsRecommended, ModifiedUtc = DateTimeOffset.UtcNow }; return(View(model)); }
public async Task <IActionResult> Update(BookEdit editedBook) { // Todo: Validate it, update it, redirect if (!ModelState.IsValid) { return(View("Edit", editedBook)); } else { var storedBook = await _dataContext.Books.SingleAsync(b => b.Id == editedBook.Id); storedBook.Title = editedBook.Title; storedBook.Author = editedBook.Author; storedBook.NumberOfPages = editedBook.NumberOfPages; await _dataContext.SaveChangesAsync(); TempData["flash"] = "Updated your book"; return(RedirectToAction("index")); } }
public bool UpdateBook(BookEdit bookToBeUpdated) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Books .Single(e => e.BookId == bookToBeUpdated.BookId); entity.Title = bookToBeUpdated.Title; entity.SeriesTitle = bookToBeUpdated.SeriesTitle; entity.Isbn = bookToBeUpdated.Isbn; entity.Rating = bookToBeUpdated.Rating; entity.Genre = bookToBeUpdated.Genre; entity.Language = bookToBeUpdated.Language; entity.Publisher = bookToBeUpdated.Publisher; entity.IsEbook = bookToBeUpdated.IsEbook; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id) { var service = CreateBookService(); var detail = service.GetBookById(id); var model = new BookEdit { BookId = detail.BookId, TypeOfBook = detail.TypeOfBook, Title = detail.Title, Author = detail.Author, IsFiction = detail.IsFiction, IsNewRelease = detail.IsNewRelease, IsBestSeller = detail.IsBestSeller, Price = detail.Price, Inventory = detail.Inventory, Description = detail.Description, }; return(View(model)); }
public bool UpdateBook(BookEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Books .Single(e => e.BookID == model.BookID); // && e.OwnerID == _userID);//This is Linq entity.BookID = model.BookID; entity.Title = model.Title; entity.Author = model.Author; entity.Description = model.Description; entity.YearPublished = model.YearPublished; entity.DateRead = model.DateRead; entity.IsRecommended = model.IsRecommended; entity.ModifiedUtc = DateTimeOffset.UtcNow; return(ctx.SaveChanges() == 1); } }
public bool UpdateBook(BookEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Book .Single(e => e.BookId == model.BookId); entity.BookId = model.BookId; entity.TypeOfBook = model.TypeOfBook; entity.Title = model.Title; entity.Author = model.Author; entity.IsFiction = model.IsFiction; entity.IsNewRelease = model.IsNewRelease; entity.IsBestSeller = model.IsBestSeller; entity.Price = model.Price; entity.Inventory = model.Inventory; entity.Description = model.Description; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, BookEdit bookToBeEdited) { if (!ModelState.IsValid) { return(View(bookToBeEdited)); } if (bookToBeEdited.BookId != id) { ModelState.AddModelError("", "ID does not match an existing item, please try again."); return(View(bookToBeEdited)); } var service = new BookService(); if (service.UpdateBook(bookToBeEdited)) { TempData["SaveResult"] = "Your book was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your book could not be updated."); return(View(bookToBeEdited)); }
public ActionResult Edit(int id) { var service = CreateBookService(); var detail = service.GetBookById(id); var model = new BookEdit { BookId = detail.BookId, Title = detail.Title, PublicationDate = detail.PublicationDate, ISBN = detail.ISBN, GenreOfBook = detail.GenreOfBook, FormatOfBook = detail.FormatOfBook, LoanedTo = detail.LoanedTo, Narrator = detail.Narrator, Translator = detail.Translator, Illustrator = detail.Illustrator, IsFirstEdition = detail.IsFirstEdition, IHaveRead = detail.IHaveRead, IOwn = detail.IOwn }; return(View(model)); }