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));
        }
예제 #2
0
    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);
    }
예제 #3
0
        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));
        }
예제 #4
0
 public void Adicionar(BibliotecaAtivo novoAtivo)
 {
     _context.Add(novoAtivo);
     _context.SaveChanges();
 }
예제 #5
0
 public void Adicionar(CheckOut novoVerificarSaida)
 {
     _context.Add(novoVerificarSaida);
     _context.SaveChanges();
 }
예제 #6
0
 public void Add(Books newBook)
 {
     _context.Add(newBook);
     _context.SaveChanges();
 }