public bool ExistEntry(int entrieid)
 {
     using (var ctx = new FoodCaloriesEntities())
     {
         return ctx.Entries.Any(b => b.IdEntry == entrieid);
     }
 }
 public Food GetFoodById(int foodid)
 {
     using (var ctx = new FoodCaloriesEntities())
     {
         var query = ctx.Food.Include("TypeFood").Include("Seller").FirstOrDefault(b => b.IdFood == foodid);
         return query;
     }
 }
 public Entries GetDairiesEntriesById(int entrieid)
 {
     using (var ctx = new FoodCaloriesEntities())
     {
         var query = ctx.Entries.Include("Diary").FirstOrDefault(b => b.IdEntry == entrieid);
         return query;
     }
 }
 public Diary GetDairiesById(string username, DateTime dairyid)
 {
     using (var ctx = new FoodCaloriesEntities())
     {
         var query = ctx.Diary.FirstOrDefault(b => b.UserName == username && b.CurrentDate == dairyid);
         return query;
     }
 }
 public IEnumerable<Food> GetAllFoods()
 {
     using (var ctx = new FoodCaloriesEntities())
     {
         var query = ctx.Food.Include("TypeFood").Include("Seller").ToList();
         return query;
     }
 }
 public int EntrieCount(string username, DateTime dairyid)
 {
     using (var ctx = new FoodCaloriesEntities())
     {
         return ctx.Entries.Include("Diary")
                            .Where(b => b.Diary.CurrentDate == dairyid && b.Diary.UserName == username).Count();
     }
 }
 public bool AddEntries(Entries entries)
 {
     using (var ctx = new FoodCaloriesEntities())
     {
         ctx.Entries.Add(entries);
         ctx.SaveChanges();
     }
     return true;
 }
 public bool DeleteEntrie(DateTime dairyid, int entrieid)
 {
     using (var ctx = new FoodCaloriesEntities())
     {
         var entity = ctx.Entries.FirstOrDefault(b => b.IdEntry == entrieid);
         ctx.Entries.Remove(entity);
         ctx.SaveChanges();
     }
     return true;
 }
 public Seller GetSellerById(int foodid,int sellerid)
 {
     using (var ctx = new FoodCaloriesEntities())
     {
         var query = ctx.Seller.FirstOrDefault(b => b.IdSeller == sellerid && b.IdFood==foodid);
         return query;
     }
 }
 public IEnumerable<Seller> GetSellerByFood(int foodid)
 {
     using (var ctx = new FoodCaloriesEntities())
     {
         var query = ctx.Seller.Where(b => b.IdFood == foodid).ToList();
         return query;
     }
 }
 public void UpdateEntrie(Entries entity,DateTime dairyid, int entrieid )
 {
     using (var ctx = new FoodCaloriesEntities())
     {
         var entrie = ctx.Entries.Include("Diary").FirstOrDefault(b=>b.IdEntry==entrieid && b.Diary.CurrentDate==dairyid);
         entrie.Quantity = entity.Quantity;
         ctx.SaveChanges();
     }
 }
 public bool IsDuplicatedEntrie(int idDiary)
 {
     using (var ctx = new FoodCaloriesEntities())
     {
         return ctx.Entries.Any(b => b.IdDairy == idDiary);
     }
 }
 IEnumerable<Entries> IRepository.GetDairiesEntries(string username, DateTime dairyid, int page, int pagesize)
 {
     using (var ctx = new FoodCaloriesEntities())
     {
         var query = ctx.Entries.Include("Diary")
                        .Where(b=>b.Diary.CurrentDate==dairyid && b.Diary.UserName==username).ToList();
         var result=query
                        .OrderBy(b=>b.Description)
                        .Skip(pagesize*page)
                        .Take(pagesize)
                        .ToList();
         return result;
     }
 }
 IEnumerable<Diary> IRepository.GetDairies(string username)
 {
     using (var ctx = new FoodCaloriesEntities())
     {
         var query = ctx.Diary.ToList();
         return query;
     }
 }