suppose in entity framework, i have the following models:
public class User
{
public int UserId { get; set; }
public string Name { get; set; }
public virtual ICollection<Item> Items { get; set; }
}
public class Item
{
public int ItemId { get; set; }
public string Name { get; set; }
public virtual User User{ get; set; }
}
that is a user can have many items, but an item has only one user. Now in asp web api i create one user and one item with a POST request: for example for the user i have the UsersController with this method:
public IHttpActionResult PostUser(User user)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
db.Users.Add(user);
db.SaveChanges();
return CreatedAtRoute("DefaultApi", new { id = user.Id }, user);
}
Now if i want update the created user, assigning to him the created item, how can i achieve it? I must call the PUT method on the UsersController right? What's the request body json object?
Thanks