public async Task <ActionResult> PostAsync([FromBody] CustomerViewModel customer) { if (!ModelState.IsValid) { var errors = ModelState .Select(x => x.Value.Errors) .Where(y => y.Count > 0) .ToList(); return(BadRequest(errors)); } var customerAdded = await _customerService.AddNewCustomerAsync(customer.Name, customer.Email); if (customerAdded == null) { return(Conflict($"Email {customer.Email} is already being used")); } return(Created($"/api/customer/{customerAdded.Id}", new CustomerViewModel() { Id = customerAdded.Id.ToString(), Name = customerAdded.Name, Email = customerAdded.Email })); }
public async Task <ActionResult> AddCustomerAsync(CustomerRequestModel customerRequestModel) { var customer = await _customerService.AddNewCustomerAsync(customerRequestModel); return(Ok(customer)); }