I want to send an object via HttpResponseMessage
from my client side code and read that object on the server side and save userId alongside.
My client side looks like this:
public async Task<ViewResult> Add(Car car)
{
Car c;
using (Database db = new Database())
{
c = db.Cars.First(x => x.Id == car.Id);
}
HttpClient client = new HttpClient();
string json = JsonConvert.SerializeObject(c);
HttpContent httpContent = new StringContent(json);
string url = "https://localhost:5001/api/cars/Saved/userId = " + AccountController.curentUser;
HttpResponseMessage response = await client.PostAsync(url, httpContent);
return View("~/Views/Car/PreviewCar.cshtml");
}
and on the server-side, it should look something like these
[HttpPost("Saved/userId = {userId}")]
public async Task<ActionResult<CarS>> PostSavedCar(string userId)
{
// car = get from client side
car.UserId = userId;
_context.SavedCars.Add(car);
await _context.SaveChangesAsync();
return CreatedAtAction("GetSavedCar", new { id = car.Id }, car);
}
I don't know what should I put in that comment section to get the object and then deserialize it?