コード例 #1
0
ファイル: DataManager.cs プロジェクト: Yuval911/FoodAPI
 public void Add(Food food)
 {
     using (FoodDBEntities foodDBEntities = new FoodDBEntities())
     {
         foodDBEntities.Foods.Add(food);
         foodDBEntities.SaveChanges();
     }
 }
コード例 #2
0
ファイル: DataManager.cs プロジェクト: Yuval911/FoodAPI
 public void Remove(int id)
 {
     using (FoodDBEntities foodDBEntities = new FoodDBEntities())
     {
         Food food = foodDBEntities.Foods.ToList().Find(f => f.ID == id);
         foodDBEntities.Foods.Remove(food);
         foodDBEntities.SaveChanges();
     }
 }
コード例 #3
0
ファイル: DataManager.cs プロジェクト: Yuval911/FoodAPI
        public void Update(Food food)
        {
            using (FoodDBEntities foodDBEntities = new FoodDBEntities())
            {
                Food currentFood = foodDBEntities.Foods.SingleOrDefault(f => f.ID == food.ID);

                if (currentFood != null)
                {
                    currentFood.Name = food.Name;
                    currentFood.Ingridients = food.Ingridients;
                    currentFood.Calories = food.Calories;
                    currentFood.Grade = food.Grade;
                }

                foodDBEntities.SaveChanges();
            }
        }