示例#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();
            }
        }