When creating a new record in the tab I need to get the id of my main screen and send it along with the new object. Currently I have this code:
public async Task<IHttpActionResult> PostMenuProduct(MenuProduct MenuProduct)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
db.MenuProducts.Add(MenuProduct);
await db.SaveChangesAsync();
if (MenuProduct.MenuIdAux != null)
{
RelationshipMenuProductWithMenu relationship = new RelationshipMenuProductWithMenu
{
MenuProductId = MenuProduct.Id,
MenuId = Convert.ToInt32(MenuProduct.MenuIdAux)
};
await AddRelationshipMenuProductWithMenu(relationship);
}
return CreatedAtRoute("DefaultApi", new { id = MenuProduct.Id }, MenuProduct);
}
In this case I add MenuIdAux
to the model to send the Id of my main screen along with the new object. How could I create this relationship without having to add this parameter in my MenuProduct
model? I tried to pass as parameter in the post but HttpPost
would not accept.