public async Task <bool> UpdateBreedAsync(BreedEntity breedEntity) { var breedToUpdate = await _dbContext.Breeds.FirstOrDefaultAsync(c => c.Id == breedEntity.Id); _dbContext.Entry(breedToUpdate).CurrentValues.SetValues(breedEntity); return(true); }
public async Task <IActionResult> PutBorrowing(int borrowerid, int inventoryid, Borrowing borrowing) { if (borrowerid != borrowing.BorrowerID || inventoryid != borrowing.InventoryID || !ModelState.IsValid) { return(BadRequest(ModelState.SelectMany(x => x.Value.Errors))); } _context.Entry(borrowing).State = EntityState.Modified; InventoryItem item = await _context.InventoryItems.FirstOrDefaultAsync(i => i.InventoryID == inventoryid); try { if (borrowing.ReturnDate != null) //I de allra flesta fall är nu boken återlämnad. { item.Available = true; //Skulle väl vara i ev. klientprogrammet som säkerheten gällande returdatum ska skötas? } await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BorrowingExists(inventoryid, borrowerid)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutBorrower(int id, Borrower borrower) { if (id != borrower.BorrowerID || !ModelState.IsValid) { return(BadRequest(ModelState.SelectMany(x => x.Value.Errors))); } _context.Entry(borrower).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BorrowerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public virtual void Delete(TEntity entityToDelete) { if (Context.Entry(entityToDelete).State == EntityState.Detached) { DbSet.Attach(entityToDelete); } DbSet.Remove(entityToDelete); }
/* * public MovieEntity CreateMovie(MovieEntity movie) * { * int newId; * var lastMovie = movies.OrderByDescending(s => s.Id).FirstOrDefault(); * { * newId = lastMovie.Id + 1; * } * movie.Id = newId; * movies.Add(movie); * return movie; * }*/ public void CreateMovie(MovieEntity movie) { //_dbContext.Entry(movie.Production).State = EntityState.Unchanged; if (movie.Production != null) { _dbContext.Entry(movie.Production).State = EntityState.Unchanged; } _dbContext.Movies.Add(movie); }
public void CreateHero(HeroEntity heroEntity) { if (heroEntity.Breed != null) { _dbContext.Entry(heroEntity.Breed).State = EntityState.Unchanged; } _dbContext.Heroes.Add(heroEntity); }
public void CreateBook(BookEntity book) { /**var latestBook = books.OrderByDescending(b => b.Id).FirstOrDefault(); * var nextBookId = latestBook == null ? 1 : latestBook.Id + 1; * book.Id = nextBookId; * books.Add(book); * return book;*/ libraryDbContext.Entry(book.Author).State = EntityState.Unchanged; libraryDbContext.Books.Add(book); }
public ActionResult BooksUpdate([DataSourceRequest] DataSourceRequest request, BookViewModel book) { if (ModelState.IsValid) { var db = new LibraryDbContext(); var category = db.Categories.FirstOrDefault(x => x.Name == book.CategoryName); var oldBook = db.Books.Single(x => x.Id == book.Id); if (oldBook.Category.Name != book.CategoryName) { oldBook.Category = category; UpdateBookFields(book, oldBook); category.Books.Add(oldBook); db.SaveChanges(); } else { UpdateBookFields(book, oldBook); db.Entry(oldBook).State = EntityState.Modified; db.SaveChanges(); } } return(Json(new[] { book }.ToDataSourceResult(request, ModelState))); }
public async Task <IActionResult> PutLibraryAssett([FromRoute] int id, [FromBody] LibraryAsset libraryAssett) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != libraryAssett.Id) { return(BadRequest()); } _context.Entry(libraryAssett).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LibraryAssettExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IHttpActionResult PutMember(int id, Member member) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != member.MemberId) { return(BadRequest()); } db.Entry(member).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!MemberExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void Update(T entity) { _context.Entry(entity).State = EntityState.Modified; _context.Attach(entity); _context.Update(entity); Save(); }
public async Task <IActionResult> PutBookAuthor(int authorid, string isbn, BookAuthor bookAuthor) { if (authorid != bookAuthor.AuthorID || isbn != bookAuthor.ISBN || !ModelState.IsValid) { return(BadRequest(ModelState.SelectMany(x => x.Value.Errors))); } _context.Entry(bookAuthor).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookAuthorExists(authorid, isbn)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Put([FromRoute] int id, [FromBody] Book book) { if (id != book.IdBook) { return(BadRequest()); } _context.Entry(book).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookIdExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutBook(int id, BookDTO book) { if (id != book.Id) { return(BadRequest()); } var b = _bookServices.EditBook(id, book); _context.Entry(b).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
void IRepositorry.IRepository <Book> .Update(Book entity) { var entry = db.Entry(entity); entry.State = EntityState.Modified; db.SaveChanges(); }
public bool UpdateCompany(CompanyEntity companyModel) { var companyToUpdate = _dbContext.Companies.FirstOrDefault(c => c.Id == companyModel.Id); _dbContext.Entry(companyToUpdate).CurrentValues.SetValues(companyModel); /*if (companyModel.Name != null) * { * _dbContext.Entry(companyModel).Property(p => p.Name).IsModified = true; * }*/ /*companyToUpdate.CEO = companyModel.CEO ?? companyToUpdate.CEO; * companyToUpdate.Country = companyModel.Country ?? companyToUpdate.Country; * companyToUpdate.FundationDate = companyModel.FundationDate ?? companyToUpdate.FundationDate; * companyToUpdate.Name = companyModel.Name ?? companyToUpdate.Name;*/ return(true); }
public Book Update(Book entity) { if (entity == null) { return(null); } var existing = _context.Books.FirstOrDefault(b => b.Id == entity.Id); if (existing != null) { _context.Entry(existing).CurrentValues.SetValues(entity); _context.Entry(existing).Property("AddedDate").IsModified = false; } _context.SaveChanges(); return(existing); }
//Book Delete Database// public void Delete(Book book) { using (LibraryDbContext _context = new LibraryDbContext()) { var entity = _context.Entry(book); entity.State = EntityState.Deleted; _context.SaveChanges(); } }
//Delete Customer Databse// public void Delete(Customer customer) { using (LibraryDbContext _context = new LibraryDbContext()) { var entity = _context.Entry(customer); entity.State = EntityState.Deleted; _context.SaveChanges(); } }
//Orders Update Database// public void Update(Orders orders) { using (LibraryDbContext _context = new LibraryDbContext()) { var entity = _context.Entry(orders); entity.State = EntityState.Modified; _context.SaveChanges(); } }
//Manager Update Database// public void Update(Manager manager) { using (LibraryDbContext _context = new LibraryDbContext()) { var entity = _context.Entry(manager); entity.State = EntityState.Modified; _context.SaveChanges(); } }
public ActionResult EditBook(Book book) { if (book == null || !database.Books.Contains(book)) { return(HttpNotFound()); } database.Entry(book).State = EntityState.Modified; database.SaveChanges(); return(PartialView("Partial", database.Books.ToList())); }
public ActionResult Edit([Bind(Include = "BookId,BookName,Status,BookCategory,BookAuthor")] Book book) { if (ModelState.IsValid) { db.Entry(book).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(book)); }
public ActionResult Edit([Bind(Include = "Id,GenreName")] Genre genre) { if (ModelState.IsValid) { db.Entry(genre).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(genre)); }
public ActionResult Edit([Bind(Include = "BookId,Title,Author,Genre,Format,YearPublished")] Book book) { if (ModelState.IsValid) { db.Entry(book).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(book)); }
public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,UserName")] Writer writer) { if (ModelState.IsValid) { db.Entry(writer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(writer)); }
public ActionResult Edit([Bind(Include = "MemberId,MemberName,Status,Age,Gender")] Member member) { if (ModelState.IsValid) { db.Entry(member).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(member)); }
public ActionResult Edit([Bind(Include = "Id,Name,Url")] Pictures pictures) { if (ModelState.IsValid) { db.Entry(pictures).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(pictures)); }
public ActionResult Put(int id, Book book) { if (id != book.Id) { return(BadRequest()); } _db.Entry(book).State = EntityState.Modified; _db.SaveChanges(); return(CreatedAtAction(nameof(Get), new { id = book.Id }, book)); }
public ActionResult Edit([Bind(Include = "BookIssueId,MemberId,BookId,DateOfIssue,Status")] BookIssue bookIssue) { if (ModelState.IsValid) { db.Entry(bookIssue).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BookId = new SelectList(db.Books, "BookId", "BookName", bookIssue.BookId); ViewBag.MemberId = new SelectList(db.Members, "MemberId", "MemberName", bookIssue.MemberId); return(View(bookIssue)); }
public ActionResult CategoriesUpdate([DataSourceRequest]DataSourceRequest request, CategoryViewModel category) { if (ModelState.IsValid) { var db = new LibraryDbContext(); var newCategory = new Category() { Id = category.Id, Name = category.Name }; db.Categories.Attach(newCategory); db.Entry(newCategory).State = EntityState.Modified; db.SaveChanges(); } return Json(new[] { category }.ToDataSourceResult(request, ModelState)); }
public ActionResult BooksUpdate([DataSourceRequest]DataSourceRequest request, BookViewModel book) { if (ModelState.IsValid) { var db = new LibraryDbContext(); var category = db.Categories.FirstOrDefault(x => x.Name == book.CategoryName); var oldBook = db.Books.Single(x => x.Id == book.Id); if (oldBook.Category.Name != book.CategoryName) { oldBook.Category = category; UpdateBookFields(book, oldBook); category.Books.Add(oldBook); db.SaveChanges(); } else { UpdateBookFields(book, oldBook); db.Entry(oldBook).State = EntityState.Modified; db.SaveChanges(); } } return Json(new[] { book }.ToDataSourceResult(request, ModelState)); }