Пример #1
0
 public List <Food> GetByAboveCalory(int CalNumber)
 {
     using (FoodDBEntities ResEntities = new FoodDBEntities())
     {
         return(ResEntities.Foods.Where(fo => fo.Calories > CalNumber).ToList());
     }
 }
Пример #2
0
 public List <Food> GetByName(string name)
 {
     using (FoodDBEntities ResEntities = new FoodDBEntities())
     {
         return(ResEntities.Foods.Where(fo => fo.Name.ToUpper().Contains(name.ToUpper())).ToList());
     }
 }
Пример #3
0
 public Food GetById(int id)
 {
     using (FoodDBEntities ResEntities = new FoodDBEntities())
     {
         return(ResEntities.Foods.FirstOrDefault(fo => fo.ID == id));
     }
 }
Пример #4
0
 public void RemoveFood(int id)
 {
     using (FoodDBEntities ResEntities = new FoodDBEntities())
     {
         ResEntities.Foods.Remove(ResEntities.Foods.FirstOrDefault(fo => fo.ID == id));
         ResEntities.SaveChanges();
     }
 }
Пример #5
0
 public void AddFood(Food f)
 {
     using (FoodDBEntities ResEntities = new FoodDBEntities())
     {
         ResEntities.Foods.Add(f);
         ResEntities.SaveChanges();
     }
 }
Пример #6
0
 public List <Food> SearchFoodsByCriteria(string name, int maxCal, int minCal, int minGrade)
 {
     using (FoodDBEntities ResEntities = new FoodDBEntities())
     {
         return(ResEntities.Foods.Where(
                    fo => fo.Calories > minCal &&
                    (fo.Grade < int.MaxValue && fo.Grade > minGrade) &&
                    fo.Calories < maxCal && (fo.Name == "" || fo.Name.ToUpper().Contains(name.ToUpper()))).ToList());
     }
 }
Пример #7
0
        public List <Food> GetAll()
        {
            List <Food> foods;

            using (FoodDBEntities ResEntities = new FoodDBEntities())
            {
                foods = ResEntities.Foods.ToList();
            }
            return(foods);
        }
Пример #8
0
        public void UpdateFood(Food f)
        {
            Food food = new Food();

            using (FoodDBEntities ResEntities = new FoodDBEntities())
            {
                food             = ResEntities.Foods.FirstOrDefault(fo => fo.ID == f.ID);
                food.Name        = f.Name;
                food.Ingridients = f.Ingridients;
                food.Calories    = f.Calories;
                food.Grade       = f.Grade;
                ResEntities.SaveChanges();
            }
        }