コード例 #1
0
 public List <Food> GetFoodBiggerThanCalory(int calory)
 {
     using (FoodDBEntities foodDBEntities = new FoodDBEntities())
     {
         return(foodDBEntities.Foods.Where(m => m.Calories > calory).ToList());
     }
 }
コード例 #2
0
 public List <Food> GetFoodsByFilter(int mincalory, int maxcalory, string name, int grade)
 {
     using (FoodDBEntities foodDBEntities = new FoodDBEntities())
     {
         return(foodDBEntities.Foods.Where(m => m.Calories > mincalory && m.Calories < maxcalory && m.Grade > grade &&
                                           (name == "" || m.Name.ToUpper().Contains(name.ToUpper()))).ToList());
     }
 }
コード例 #3
0
        public void AddToDB(Food food)
        {
            using (FoodDBEntities foodDBEntities = new FoodDBEntities())
            {
                foodDBEntities.Foods.Add(food);

                foodDBEntities.SaveChanges();
            }
        }
コード例 #4
0
        public List <Food> Foods()
        {
            using (FoodDBEntities foodDBEntities = new FoodDBEntities())
            {
                List <Food> foods = foodDBEntities.Foods.ToList();

                return(foods);
            }
        }
コード例 #5
0
        public void RemoveFromDB(int id)
        {
            using (FoodDBEntities foodDBEntities = new FoodDBEntities())
            {
                Food result = foodDBEntities.Foods.SingleOrDefault(b => b.ID == id);
                if (result != null)
                {
                    foodDBEntities.Foods.Remove(result);
                }

                foodDBEntities.SaveChanges();
            }
        }
コード例 #6
0
 public void UpdateDB(Food food, int id)
 {
     using (FoodDBEntities foodDBEntities = new FoodDBEntities())
     {
         Food result = foodDBEntities.Foods.SingleOrDefault(b => b.ID == id);
         if (result != null)
         {
             result.Calories    = food.Calories;
             result.Grade       = food.Grade;
             result.Ingridients = food.Ingridients;
             result.Name        = food.Name;
             foodDBEntities.SaveChanges();
         }
     }
 }