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)); }
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)); }
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)); } }