Exemple #1
0
        public async Task <IActionResult> PutPizza(int id, Pizza pizza)
        {
            if (id != pizza.Id)
            {
                return(BadRequest());
            }

            _context.Entry(pizza).State = EntityState.Modified;

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

            return(NoContent());
        }
Exemple #2
0
            private async Task <HungryPizzaAPIContext> GetDatabaseContext()
            {
                var options = new DbContextOptionsBuilder <HungryPizzaAPIContext>()
                              .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                              .Options;
                var databaseContext = new HungryPizzaAPIContext(options);

                databaseContext.Database.EnsureCreated();
                if (await databaseContext.Pizza.CountAsync() <= 0)
                {
                    databaseContext.Pizza.Add(new Pizza()
                    {
                        Id        = 1,
                        Sabor     = "Sabor teste",
                        Descricao = "Descrição teste"
                    });
                    await databaseContext.SaveChangesAsync();
                }
                return(databaseContext);
            }
            private async Task <HungryPizzaAPIContext> GetDatabaseContext()
            {
                var options = new DbContextOptionsBuilder <HungryPizzaAPIContext>()
                              .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                              .Options;
                var databaseContext = new HungryPizzaAPIContext(options);

                databaseContext.Database.EnsureCreated();
                if (await databaseContext.Pedido.CountAsync() <= 0)
                {
                    for (int i = 1; i <= 10; i++)
                    {
                        databaseContext.Pedido.Add(new Pedido()
                        {
                            Id = i
                        });
                        await databaseContext.SaveChangesAsync();
                    }
                }
                return(databaseContext);
            }