Esempio n. 1
0
        public ActionResult Post(Heroi model)
        {
            try
            {
                #region
                //Ele criou um heroi novo acrescentando uma lista de armas. Essa seção poderia ser linear mas a organização dessa forma não interfere na programação ex: var heroi = new Heroi { assim, assado };
                //var heroi = new Heroi
                //{
                //    Nome = "Homem de Ferro",
                //    Armas = new List<Arma>
                //    {
                //        new Arma {Nome = "Mac 3"},
                //        new Arma {Nome = "Mac 5"}
                //    }
                //};

                //Aqui salvou esse heroi dentro das tabelas qu estão na parte EFCore.Dominio atravez do -context, que é responsavel por fazer essa conexão. E salvou essas alterações dentro do SQL utilizando o SaveChanges().
                #endregion


                _context.Herois.Add(model);
                _context.SaveChanges();
                return(Ok("BAZINGA"));
            }
            catch (Exception ex)
            {
                return(BadRequest($"Erro: {ex}"));
            }
        }
        public ActionResult GetAddRange()
        {
            _context.AddRange(
                new Heroi {
                Nome = "Capitão América"
            },
                new Heroi {
                Nome = "Doutor Estranho"
            },
                new Heroi {
                Nome = "Pantera Negra"
            },
                new Heroi {
                Nome = "Viúva Negra"
            },
                new Heroi {
                Nome = "Hulk"
            },
                new Heroi {
                Nome = "Gavião Arqueiro"
            },
                new Heroi {
                Nome = "Capitã Marvel"
            }
                );
            _context.SaveChanges();

            return(Ok());
        }
        public ActionResult Get(string nameHero)
        {
            var heroi = new Heroi {
                Nome = nameHero
            };

            _context.Herois.Add(heroi);
            _context.SaveChanges();
            return(Ok());
        }
Esempio n. 4
0
        public ActionResult Get(string nameHero)
        {
            //var heroi = new Heroi { Nome = nameHero };
            var heroi = _context.Herois.Where(x => x.Id == 3).FirstOrDefault();

            heroi.Nome = "Homem Aranha";
            //_context.Herois.Add(heroi);
            _context.SaveChanges();
            return(Ok());
        }
Esempio n. 5
0
        public ActionResult Get(string nameHero)
        {
            var heroi = _context.Herois
                        .Where(h => h.Id == 3)
                        .FirstOrDefault();

            heroi.Nome = nameHero;
            _context.SaveChanges();
            return(Ok());
        }
Esempio n. 6
0
        public ActionResult <string> Get(string nameHero)
        {
            //var heroi = new Heroi { Nome = nameHero };
            var heroi = _context.Herois.Where(h => h.Id == 2).FirstOrDefault();

            heroi.Nome = "Doutor Estranho";
            //_context.Add(heroi);
            _context.SaveChanges();
            return(Ok());
        }
Esempio n. 7
0
        public ActionResult Post(Heroi model)
        {
            try {
                _context.Herois.Add(model);
                _context.SaveChanges();

                return(Ok("BAZINGA"));
            } catch (Exception e) {
                return(BadRequest($"Error: {e}"));
            }
        }
        public ActionResult Get(int id)
        {
            var heroi = new Heroi()
            {
                Nome = "Spider-Man"
            };

            _context.Herois.Add(heroi);
            _context.SaveChanges();

            return(Ok());
        }
Esempio n. 9
0
 public ActionResult Post(Heroi model)
 {
     try
     {
         _context.Herois.Add(model);
         _context.SaveChanges();
         return(Ok("feito"));
     }
     catch (Exception ex)
     {
         return(BadRequest($"Erro: {ex}"));
     }
 }
        public ActionResult Post(Batalha model)
        {
            try
            {
                _context.Batalhas.Add(model);
                _context.SaveChanges();

                return(Ok("BAZINGA"));
            }
            catch (Exception ex)
            {
                return(BadRequest($"Erro: {ex}"));
            }
        }
        public ActionResult PostBatalha(Batalha batalha)
        {
            try
            {
                _context.Batalhas.Add(batalha);
                _context.SaveChanges();

                return(Ok("Saved"));
            }
            catch (Exception ex)
            {
                return(BadRequest($"Erro: {ex}"));
            }
        }
Esempio n. 12
0
        public ActionResult <string> Get(string nameHero)
        {
            //recebe da URL a variável e salva numa var interna
            //var heroi = new Heroi { Nome = nameHero };

            //declara uma variavel e pega o valor do banco de dados, onde o Id for 3.
            var heroi = _context.Herois
                        .Where(h => h.Id == 3)
                        .FirstOrDefault();

            heroi.Nome = "Homem Aranha";
            //_context.Herois.Add(heroi);
            //_context.Add(heroi);
            _context.SaveChanges();
            return(Ok());
        }
Esempio n. 13
0
        public ActionResult <string> Get(string nameHero)
        {
            //var heroi = new Heroi { Nome = nameHero };

            // buscar item e atualizar
            var heroi = _context.Herois
                        .Where(h => h.Id == 3)
                        .FirstOrDefault();

            heroi.Nome = "Homem Aranha";

            //_context.Add(heroi);
            _context.SaveChanges();

            return(Ok());
        }
Esempio n. 14
0
        public async Task <ActionResult> Put(int id, HeroiController heroi)
        {
            try
            {
                var heroi = await _repo.getHeroiById(id)

                            if (heroi != null)
                {
                    _context.Update(model);
                    _context.SaveChanges();

                    return(OK("Bazinga"));
                }

                return(ok("Não Encontrado!"));
            }
            catch (Exception ex)
            {
                return(BadRequest($"Erro: {ex}"));
            }
        }
Esempio n. 15
0
        public ActionResult <string> AddRange(string nameHero)
        {
            _context.AddRange(
                new Heroi {
                Nome = "Capitao América"
            },
                new Heroi {
                Nome = "Doutor Estranho"
            },
                new Heroi {
                Nome = "Pantera Negra"
            },
                new Heroi {
                Nome = "Viuva Negra"
            },
                new Heroi {
                Nome = "Hulk"
            },
                new Heroi {
                Nome = "Gavião Arqueiro"
            },
                new Heroi {
                Nome = "Capitã Marvel"
            }
                );
            _context.SaveChanges();
            return(Ok());

            // var heroi = new Heroi { Nome = nameHero };
            // var listHeroi = _context.Herois
            //                .Where(h => h.Id == 3).FirstOrDefault();
            // heroi.Nome = "Homem Aranha";

            //// _context.Herois.Add(heroi);



            return(Ok());
        }
        public ActionResult Post(Heroi model)
        {
            try
            {
                //var heroi = new Heroi
                //{
                //    Nome = "Homem de Ferro",
                //    Armas = new List<Arma>
                //    {
                //        new Arma { Nome = "Mac 3" },
                //        new Arma { Nome = "Mac 5" }
                //    }
                //};

                _context.Herois.Add(model);
                _context.SaveChanges();

                return(Ok("Bazinga"));
            }
            catch (Exception ex)
            {
                return(BadRequest($"Erro: {ex}"));
            }
        }
Esempio n. 17
0
 public ActionResult Post([FromBody] Heroi h)
 {
     _context.Add(h);
     _context.SaveChanges();
     return(new ObjectResult(h));
 }