public ActionResult <Car> Create([FromBody] Car newCar) { try { newCar.UserId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; return(Ok(_cs.Create(newCar))); } catch (System.Exception err) { return(BadRequest(err.Message)); } }
public ActionResult <Car> Create([FromBody] Car newCar) { try { Claim user = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier); if (user == null) { throw new Exception("Must be logged in to create."); } newCar.UserId = user.Value; return(Ok(_cs.Create(newCar))); } catch (System.Exception err) { return(BadRequest(err.Message)); } }