public Livro Update(Livro livro)
 {
     DbEntityEntry entry = context.Entry(livro);
     entry.State = EntityState.Modified;
     context.SaveChanges();
     return livro;
 }
Ejemplo n.º 2
0
        public Livro Update(Livro livro)
        {
            Validator.Validate(livro);

            var updated = _livroRepository.Update(livro);

            return updated;
        }
Ejemplo n.º 3
0
        public Livro Create(Livro livro)
        {
            Validator.Validate(livro);

            var saved = _livroRepository.Save(livro);

            return saved;
        }
Ejemplo n.º 4
0
        public static Livro GetLivro()
        {
            Livro livro = new Livro();
               livro.Id = 1;
               livro.Nome = "Teste2";
               livro.Descricao = "Teste2";
               livro.Preco = 60.00;
               livro.AutorId = 1;
               livro.Autor = new Autor()
               {
               Id=1,
               Nome = "Autor teste",
               cpf = "059.893.186-42",
               telefone ="(49)3222-2222"
               };

               return livro;
        }
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                Livro livro = new Livro();
                livro.Nome = collection.GetValue("Nome").AttemptedValue;
                livro.Preco = Convert.ToDouble(collection.GetValue("Preco").AttemptedValue);
                livro.Descricao = collection.GetValue("Descricao").AttemptedValue;

                Autor autor = new Autor();
                livro.AutorId = Convert.ToInt32(collection.GetValue("AutorId").AttemptedValue); ;
                livro.Autor= autor;
                _repository.Save(livro);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
 public Livro Save(Livro livro)
 {
     var novo = context.Livros.Add(livro);
     context.SaveChanges();
     return novo;
 }