public void AddFood(Food f) { using (FoodDBEntities fd = new FoodDBEntities()) { fd.Foods.Add(f); fd.SaveChanges(); } }
public void Delete(int id) { using (FoodDBEntities fd = new FoodDBEntities()) { Food food = fd.Foods.FirstOrDefault(f => f.ID == id); fd.Foods.Remove(food); fd.SaveChanges(); } }
public void UpdateFood(Food f) { Food food = new Food(); using (FoodDBEntities fd = new FoodDBEntities()) { food = fd.Foods.FirstOrDefault(fo => fo.ID == f.ID); food.Calories = f.Calories; food.Grade = f.Grade; food.Ingridients = f.Ingridients; food.Name = f.Name; fd.SaveChanges(); } }