//startup class call this method
        public void SeedData(int nCustomers, int nOrders)
        {
            if (!_ctx.Customers.Any())
            {
                SeedCustomers(nCustomers);
                _ctx.SaveChanges();
            }

            if (!_ctx.Orders.Any())
            {
                SeedOrders(nOrders);
                _ctx.SaveChanges();
            }

            if (!_ctx.Servers.Any())
            {
                SeedServers();
                _ctx.SaveChanges();
            }
        }
Exemple #2
0
        public IActionResult Post([FromBody] Customer customer)
        {
            if (customer == null)
            {
                return(BadRequest());
            }

            _ctx.Customers.Add(customer);
            _ctx.SaveChanges();

            return(CreatedAtRoute("GetCustomer", new { id = customer.Id }, customer));
        }