//update ingredient in database public ingredientDto PutIngredient(ingredientDto IngredientDto, ref string f) { using (HealthyMenuEntities db = new HealthyMenuEntities()) { try { ingredient Ingredient = db.ingredients.FirstOrDefault(x => x.id == IngredientDto.id); if (Ingredient == null) { f = "לא קיים"; return(null); } Ingredient.id = IngredientDto.id; Ingredient.CDescription = IngredientDto.CDescription; Ingredient.RecommendedDoseMale = IngredientDto.RecommendedDoseMale; Ingredient.RecommendedDoseFemale = IngredientDto.RecommendedDoseFemale; Ingredient.UnitCode = IngredientDto.UnitCode; return(Convertion.IngredientConvertion.convert(Ingredient)); } catch { return(null); } } }
//convert one ingredient to ingredientDto public static ingredientDto convert(ingredient Ingredient) { ingredientDto NewIngredient = new ingredientDto(); NewIngredient.id = Ingredient.id; NewIngredient.CDescription = Ingredient.CDescription; NewIngredient.RecommendedDoseMale = Ingredient.RecommendedDoseMale; NewIngredient.RecommendedDoseFemale = Ingredient.RecommendedDoseFemale; NewIngredient.UnitCode = Ingredient.UnitCode; return(NewIngredient); }
// DELETE api/values/5 public IHttpActionResult Delete(ingredientDto value) { if (value == null) { return(BadRequest("לא נשלח מידע")); } value = service.RemoveIngredient(value); if (value == null) { return(BadRequest("מחיקה נכשלה")); } return(Ok(value)); }
// PUT api/values/5 public IHttpActionResult Put(ingredientDto value) { if (value == null) { return(BadRequest("לא נשלח מידע")); } value = service.PostIngredient(value); if (value == null) { return(BadRequest("עדכון נכשל")); } return(Ok(value)); }
//remove ingredient to database public ingredientDto RemoveIngredient(ingredientDto IngredientDto) { using (HealthyMenuEntities db = new HealthyMenuEntities()) { try { ingredient Ingredient = db.ingredients.Remove(Convertion.IngredientConvertion.convert(IngredientDto)); db.SaveChanges(); return(Convertion.IngredientConvertion.convert(Ingredient)); } catch { return(null); } } }