public async Task <Recipe> Post([FromBody] Recipe value) { var recipe = await Map(value); await _db.AddAsync(recipe); await _db.SaveChangesAsync(); // Pick up any changes that happen in the DB (triggers, etc) var dbRecipe = await _db.Recipes .Include(r => r.MakesUnit) .SingleOrDefaultAsync(r => r.Name == recipe.Name); return(Map(dbRecipe)); }
public async Task <RecipeIngredient> Put(int id, [FromBody] RecipeIngredient value) { var recipe = await Map(value); if (_db.RecipeIngredients.Any(r => r.Id == value.Id)) { _db.Update(value); } else { await _db.AddAsync(recipe); } await _db.SaveChangesAsync(); var dbRecipeIngredient = await _db.RecipeIngredients .Include(r => r.Ingredient) .Include(r => r.Unit) .SingleOrDefaultAsync(ri => ri.Ingredient.Name == value.IngredientName); return(Map(dbRecipeIngredient)); }