コード例 #1
0
        public async Task <IActionResult> CreateCustomer([FromBody] Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var _customer = await _context.Customers.FindAsync(customer.Id);

            if (_customer != null)
            {
                return(BadRequest(ModelState));
            }

            await _context.AddAsync(customer);

            await _context.SaveChangesAsync();

            return(Ok(customer));
        }