예제 #1
0
 public async Task <ActionResult <Customer> > PostCustomer([FromBody] Customer customer)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     _repo.Add(customer);
     return(CreatedAtAction(/*"DisplayRoute"*/ nameof(GetCustomer), new { id = customer.Id }, customer));
 }
예제 #2
0
        public async Task <IActionResult> Create([Bind("CustomerId,FirstName,LastName,PNr")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                customer.CustomerId = Guid.NewGuid();
                await _customersRepo.Add(customer);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
예제 #3
0
        public async Task <ActionResult <Customers> > PostCustomers(Customers customers)
        {
            // check for duplicate Email
            if (_repo.Exists(customers.Email))
            {
                return(Conflict());
            }

            try
            {
                await _repo.Add(customers);

                return(CreatedAtAction("GetCustomers", new { id = customers.Id }, customers.Id));
            }
            catch (DbUpdateException)
            {
                return(new StatusCodeResult(422));
            }
        }