//convert one ingredientsInProDto to ingredientsInPro public static ingredientsInPro convert(ingredientsInProDto IngredientInPro) { ingredientsInPro NewIngredientInPro = new ingredientsInPro(); NewIngredientInPro.id = IngredientInPro.id; NewIngredientInPro.foodID = IngredientInPro.foodID; NewIngredientInPro.ingredientsId = IngredientInPro.ingredientsId; NewIngredientInPro.countFor100gr = IngredientInPro.countFor100gr; return(NewIngredientInPro); }
// DELETE api/<controller>/5 public IHttpActionResult Delete(ingredientsInProDto value) { if (value == null) { return(BadRequest("לא נשלח מידע")); } value = service.RemoveIngredientsInPro(value); if (value == null) { return(BadRequest("מחיקה נכשלה")); } return(Ok(value)); }
// PUT api/<controller>/5 public IHttpActionResult Put(ingredientsInProDto value) { if (value == null) { return(BadRequest("לא נשלח מידע")); } value = service.PostIngredientInPro(value); if (value == null) { return(BadRequest("עדכון נכשל")); } return(Ok(value)); }
//remove ingredientInPro from database public ingredientsInProDto RemoveIngredientsInPro(ingredientsInProDto IngredientsInProDto) { using (HealthyMenuEntities db = new HealthyMenuEntities()) { try { ingredientsInPro IngredientsInPro = db.ingredientsInProes.Remove(Convertion.IngredientsInProConvertion.convert(IngredientsInProDto)); db.SaveChanges(); return(Convertion.IngredientsInProConvertion.convert(IngredientsInPro)); } catch { return(null); } } }
//update ingredientInPro in database public ingredientsInProDto PutIngredientsInPro(ingredientsInProDto IngredientsInProDto) { using (HealthyMenuEntities db = new HealthyMenuEntities()) { try { ingredientsInPro IngredientsInPro = db.ingredientsInProes.FirstOrDefault(x => x.id == IngredientsInProDto.id); if (IngredientsInPro == null) { return(null); } IngredientsInPro.id = IngredientsInProDto.id; IngredientsInPro.foodID = IngredientsInProDto.foodID; IngredientsInPro.ingredientsId = IngredientsInProDto.ingredientsId; IngredientsInPro.countFor100gr = IngredientsInProDto.countFor100gr; return(Convertion.IngredientsInProConvertion.convert(IngredientsInPro)); } catch { return(null); } } }