public async Task <IHttpActionResult> PutIngredient(int id, Containers.Models.EasyInputs.EasyIngredient ingredient) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } DB.Ingredient ingredientDb = ingredient.ToDBIngredient(); ingredientDb.Id = id; db.Entry(ingredientDb).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!IngredientExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public DB.Ingredient ToDBIngredient() { DB.Ingredient ingredient = new DB.Ingredient(); ingredient.Name = Name; return(ingredient); }
public async Task <IHttpActionResult> PostIngredient(Containers.Models.EasyInputs.EasyIngredient ingredient) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Ingredient.Add(ingredient.ToDBIngredient()); await db.SaveChangesAsync(); DB.Ingredient ingredientDb = db.Ingredient.Where(n => n.Name == ingredient.Name).FirstOrDefault(); return(CreatedAtRoute("DefaultApi", new { id = ingredientDb.Id }, ingredientDb)); }