public IHttpActionResult PutAuthor(int id, Author author) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != author.Id) { return(BadRequest()); } db.Entry(author).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AuthorExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public long InsertAuthor(Author author) { context.Authors.Add(author); context.SaveChanges(); // В этом нет необходимости, поскольку EF по после вызова SaveChanges() // сам заполняет автоинкрементные поля в добавленных объектах в соответствии // с полученными значениями для этих полей при добавлении в БД //return Convert.ToInt64(context.Database.SqlQuery<decimal>("SELECT IDENT_CURRENT('Authors')").SingleOrDefault()); return(author.Id); }
public ActionResult Edit([Bind(Include = "GenreId,GenreName")] Genre genre) { if (ModelState.IsValid) { //check if the same genre exists var genreExists = db.Genres.Count(g => g.GenreName == genre.GenreName); if (genreExists == 0) { db.Entry(genre).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); } return(View(genre)); }
public void Adicionar(BibliotecaAtivo novoAtivo) { _context.Add(novoAtivo); _context.SaveChanges(); }
public void Adicionar(CheckOut novoVerificarSaida) { _context.Add(novoVerificarSaida); _context.SaveChanges(); }
public void Add(Books newBook) { _context.Add(newBook); _context.SaveChanges(); }