// GET: api/ingredients public List <ingredientViewModel> Getingredients() { List <ingredientViewModel> rep = new List <ingredientViewModel>(); var im = db.ingredients.ToList(); foreach (var n in im) { ingredientViewModel Cvm = new ingredientViewModel(); Cvm.nom = n.nom; Cvm.calories = n.calories; Cvm.label = n.label; rep.Add(Cvm); } return(rep); }
public IHttpActionResult Getingredients(string id) { ingredients ingredients = db.ingredients.Find(id); ingredientViewModel ivm = new ingredientViewModel(); if (ingredients == null) { return(NotFound()); } else { ivm.nom = ingredients.nom; ivm.calories = ingredients.calories; ivm.label = ingredients.label; return(Ok(ivm)); } }