public ActionResult Post([FromBody] Car car) { // add the new car to the database try { _db.AddCar(car); PublishNotification(car); var result = new CreatedResult($"/api/cars/{car.Registration}", car); return(result); } catch (DuplicateCarException ex) { return(Conflict(ex.Message)); } }
public async Task <IActionResult> Post([FromBody] Car car) { try { db.AddCar(car); await PublishNewCarMessage(car); return(Redirect($"/api/cars/{car.RegistrationNumber}")); } catch (DuplicateCarException ex) { return(Conflict($"There is already a car with registration {ex.Car.RegistrationNumber} in the database!")); } }