Пример #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();
         }
     }
 }