public IEntry GetJournalEntry(int entryId, EntryType entryType)
        {
            IEntry entry = null;

            using (var entities = new DietjournalEntities())
            {
                var entryCollection = GetEntryTypeEntries(entities, entryType);
                entry = entryCollection.FirstOrDefault(e => e.Id == entryId);
            }

            return entry;
        }
        public IEnumerable<IEntry> GetJournalEntries(Guid userId, EntryType entryType, DateTime date)
        {
            var entries = new List<IEntry>();

            date = date.Date;

            using (var entities = new DietjournalEntities())
            {
                var results = from e in GetEntryTypeEntries(entities, entryType)
                              where e.UserId == userId && e.EntryDate >= date && e.EntryDate < date.AddDays(1)
                              select e;

                entries = results.ToList();
            }

            return entries;
        }
        public void SaveJournalEntry(IEntry entry)
        {
            using (var entities = new DietjournalEntities())
            {
                if (entry is FoodEntry)
                {
                    var foodEntry = (FoodEntry)entry;

                    if (entry.Id > 0)
                        entities.Attach(foodEntry);
                    else
                    {
                        entities.FoodEntries.AddObject(foodEntry);
                    }
                }

                entities.SaveChanges();
            }
        }
        public Journal GetDailyJournal(Guid userId, DateTime date)
        {
            var journal = new Journal
            {
                UserId = userId,
                Date = date,
            };

            date = date.Date;

            using (var model = new DietjournalEntities())
            {
                journal.ExerciseEnteries = model.ExerciseEntries.Where(e => e.UserId == userId && e.EntryDate >= date && e.EntryDate < date.AddDays(1)).ToList();
                journal.FoodEntries = model.FoodEntries.Where(e => e.UserId == userId && e.EntryDate >= date && e.EntryDate < date.AddDays(1)).ToList();
                journal.SupplementEntries = model.SupplementEntries.Where(e => e.UserId == userId && e.EntryDate >= date && e.EntryDate < date.AddDays(1)).ToList();
                journal.WaterEntries = model.WaterEntries.Where(e => e.UserId == userId && e.EntryDate >= date && e.EntryDate < date.AddDays(1)).ToList();
            }

            return journal;
        }
 private IEnumerable<IEntry> GetEntryTypeEntries(DietjournalEntities entities, EntryType entryType)
 {
     switch(entryType)
     {
         case EntryType.BloodPressure:
             return entities.BloodPressureEntries;
         case EntryType.Exercise:
             return entities.ExerciseEntries;
         case EntryType.Food:
             return entities.FoodEntries;
         case EntryType.Supplement:
             return entities.SupplementEntries;
         case EntryType.Water:
             return entities.WaterEntries;
         case EntryType.Weight:
             return entities.WeightEntries;
         default:
             return null;
     }
 }