2
When creating a new record in the tab I need to take the ID of my main screen and send 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
in the model to send together with the new object the id of my main screen. How I could create this relationship without having to add this parameter to my model MenuProduct
? I tried to pass as parameter in the post but the HttpPost
did not accept.
I should create a project to save my Viewmodels and then share them with the Web Api and the Asp.Net MVC project?
– user8356
@Carlosgeovanio Can be done this way, or else the Viewmodels can stay in the API project and the API project be referenced by the MVC project.
– Leonel Sanches da Silva