public void Add(Food food) { using (FoodDBEntities foodDBEntities = new FoodDBEntities()) { foodDBEntities.Foods.Add(food); foodDBEntities.SaveChanges(); } }
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(); } }
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(); } }