예제 #1
0
        public IActionResult Post([FromBody] Product newProduct)
        {
            if (newProduct == null)
            {
                return(BadRequest());
            }

            _context.Products.Add(newProduct);
            _context.SaveChanges();
            return(CreatedAtRoute("GetProduct", new { id = newProduct.Id }, newProduct));
        }
예제 #2
0
        public ProductsController(FabrikaContext context)
        {
            _context = context;

            if (_context.Products.Count() == 0)
            {
                _context.Products.Add(new Product {
                    Id = 19201, Name = "Lego Nexo Knights King I", UnitPrice = 45
                });
                _context.Products.Add(new Product {
                    Id = 23942, Name = "Lego Starwars Minifigure Jedi", UnitPrice = 55
                });
                _context.Products.Add(new Product {
                    Id = 30021, Name = "Star Wars çay takýmý ", UnitPrice = 35.50
                });
                _context.Products.Add(new Product {
                    Id = 30492, Name = "Star Wars kahve takýmý", UnitPrice = 24.40
                });

                _context.SaveChanges();
            }
        }