Beispiel #1
0
 public IngredientModel(DAL.Ingredient ingre)
 {
     this.ID          = ingre.ID;
     this.Name        = ingre.Name;
     this.Cost        = ingre.Cost;
     this.Category_ID = ingre.Category_ID;
 }
        public string AddOrUpdateIngredientInFood(Food newFood)
        {
            FoodManager foodManager = new FoodManager();
            int foodID = foodManager.GetFoodIDByName(newFood.Name);
            string res = DeleteIngredientInFood(foodID);
            if (res != "")
                return res;
            if (newFood.GetIngredients() == null)
                return "";
            foreach (Ingredient igr in newFood.GetIngredients())
            {
                res = AddOrUpdateIngredientDetails(igr.GetIngredientDetails());
                if (res != "")
                    return res;
                try
                {
                    int ingredientDetailsID = GetIngredientDetailsID(igr.Name);

                    DAL.Ingredient newIgredient = new DAL.Ingredient();
                    newIgredient.ingredientDetailsID = ingredientDetailsID;
                    newIgredient.quantity = igr.Quantity;
                    Table<DAL.Ingredient> igrTable = GetIngredientsTable();
                    igrTable.InsertOnSubmit(newIgredient);
                    igrTable.Context.SubmitChanges();

                    DAL.IngredientsInFood newIgrInFood = new DAL.IngredientsInFood();
                    newIgrInFood.foodID = foodID;
                    newIgrInFood.ingredientID = newIgredient.ingredientID;
                    Table<DAL.IngredientsInFood> igrInFoodTable = GetIngredientsInFoodTable();
                    igrInFoodTable.InsertOnSubmit(newIgrInFood);
                    igrInFoodTable.Context.SubmitChanges();
                }
                catch (Exception ex)
                {
                    return ex.Message;
                }
            }
            return "";
        }