public async Task <IHttpActionResult> PutAuthor(int id, Author author)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != author.AuthorId)
            {
                return(BadRequest());
            }

            db.Entry(author).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AuthorExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #2
0
        public ActionResult Edit(EditorBookViewModel model)
        {
            var livro = _db.Livros.Find(model.Id);

            _db.Entry <Livro>(livro).State = EntityState.Modified;
            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public bool Create(Autor autor)
        {
            try
            {
                _db.Entry <Autor>(autor).State = EntityState.Detached;
                _db.Aturores.Attach(autor);

                _db.Aturores.Add(autor);
                _db.SaveChanges();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }
        }
Beispiel #4
0
        public ActionResult Edit(EditorBookViewModel model)
        {
            var livro = new Livro();

            _db.Entry <Livro>(livro).State = System.Data.Entity.EntityState.Modified;
            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }
 public bool Update(Category category)
 {
     try
     {
         _db.Entry <Category>(category).State = EntityState.Modified;
         _db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #6
0
 public bool Update(Livro livro)
 {
     try
     {
         _db.Entry <Livro>(livro).State = EntityState.Modified;
         _db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #7
0
 public bool Update(Book book)
 {
     try
     {
         _db.Entry <Book>(book).State = EntityState.Modified;
         _db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #8
0
        public bool Update(Category category)
        {
            try
            {
                _db.Entry <Category>(category).State = EntityState.Modified;

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
 public bool Update(Author author)
 {
     try
     {
         _db.Entry <Author>(author).State = EntityState.Modified;
         _db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #10
0
        public ActionResult Edit(EditorBookViewModel model)
        {
            var livro = _db.Livros.Find(model.Id);

            livro.Nome           = model.Nome;
            livro.ISBN           = model.ISBN;
            livro.DataLancamento = model.DataLancamento;
            livro.CategoriaId    = model.CategoriaId;

            _db.Entry <Livro>(livro).State = System.Data.Entity.EntityState.Modified;
            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }
 public bool Atualizar(Autor autor)
 {
     try
     {
         // O EF é inteligente o suficiente para interpretar o que mudou no autor em relação ao que está no banco
         _context.Entry <Autor>(autor).State = EntityState.Modified;
         _context.SaveChanges();
     }
     catch
     {
         return(false);
     }
     return(true);
 }
Beispiel #12
0
        public bool Update(Categoria categoria)
        {
            try
            {
                _db.Entry <Categoria>(categoria).State = EntityState.Modified;
                _db.SaveChanges();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #13
0
        public bool Update(Autor autor)
        {
            try
            {
                _db.Entry <Autor>(autor).State = System.Data.Entity.EntityState.Modified;
                _db.SaveChanges();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #14
0
 public void Update(Book entity)
 {
     _db.Entry <Book>(entity).State = EntityState.Modified;
     _db.SaveChanges();
 }
 public void Update(Author entity)
 {
     _db.Entry <Author>(entity).State = EntityState.Modified;
     _db.SaveChanges();
 }