//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); }
//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); } } }
//get one ingredientInPro by id from database public ingredientsInProDto GetIngredientsInPro(int id) { using (HealthyMenuEntities db = new HealthyMenuEntities()) { try { ingredientsInPro IngredientsInPro = db.ingredientsInProes.FirstOrDefault(x => x.id == id); if (IngredientsInPro == null) { return(null); } 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); } } }